Home »
Archives
An Empirical Study on the Use and Misuse of Java 8 Streams
Introduction
Streaming APIs allow for big data processing of native data structures by providing MapReduce-like operations over these structures. However, unlike traditional big data systems, these data structures typically reside in shared memory accessed by multiple cores. Although popular, this emerging hybrid paradigm opens the door to possibly detrimental behavior, such as thread contention and bugs related to non-execution and non-determinism. This study explores the use and misuse of a popular streaming API, namely, Java 8 Streams. The focus is on how developers decide whether or not to run these operations sequentially or in parallel and bugs both specific and tangential to this paradigm. Our study involved analyzing 34 Java projects and 5.53 million lines of code, along with 719 manually examined code patches. Various automated, including interprocedural static analysis, and manual methodologies were employed. The results indicate that streams are pervasive, stream parallelization is not widely used, and performance is a crosscutting concern that accounted for the majority of fixes. We also present coincidences that both confirm and contradict the results of related studies. The study advances our understanding of streams, as well as benefits practitioners, programming language and API designers, tool developers, and educators alike.
Researchers
Publications
My and my research students‘ names are boldfaced, undergraduate students are italicized, and female students are underlined:
Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Baishakhi Ray. An empirical study on the use and misuse of Java 8 streams. In Heike Wehrheim and Jordi Cabot, editors, Fundamental Approaches to Software Engineering, FASE ’20, pages 97–118, Cham, April 2020. ETAPS, Springer International Publishing. (23/81; 28% acceptance rate). EAPLS Best Paper Award 🏆. [ bib | DOI | data | slides | http ]
Study Data
Subject Source Code
The set of open-source Java projects packaged as Eclipse projects used in the stream usage and characteristics studies can be downloaded as an archive. Please refer to the included README.md file for building instructions and the LICENSE.md file for licensing information. Subject source code and version history for the stream bug study can be downloaded directly from GitHub.
Raw Results
The data set consisting of the raw results produced during our study can be found on Zenodo. The directory structure is as follows:
characteristics_subject_data.csv: General attributes of the subjects used for the stream characteristics analysis.- Column
subject rawmay be the subproject for several subjects. - Some metrics, e.g., SLOC, are only associated with the first subproject for a given subject.
characteristics_subject_ages.csv: Ages of the subjects used for the stream characteristics analysis.characteristics_subject_entry_points.csv: Detailed info on entry points used in the analysis of the characteristics.characteristics_stream_execution_modes.csv: Stream execution modes.characteristics_stream_orderings.csv: Stream orderings.characteristics_stream_attributes.csv: Stream side-effects and stateful intermediate operations (SIOs).method_calls.csv: Raw data for the stream operation analysis.method_calls_subjects.csv: Data on the subjects used for the method call analysis.bugs.csv: Raw data for the stream bug study.
Presentations
Awards & Nominations
Log Level Rejuvenation for Evolving Software
Introduction

Logging—used for system events and security breaches to more informational yet essential aspects of software features—is pervasive. Given the high transactionality of today’s software, logging effectiveness can be reduced by information overload. Log levels help alleviate this problem by correlating a priority to logs that can be later filtered. As software evolves, however, levels of logs documenting surrounding feature implementations may also require modification as features once deemed important may have decreased in urgency and vice-versa. We present an automated approach that assists developers in evolving levels of such (feature) logs. The approach, based on mining Git histories and manipulating a degree of interest (DOI) model, transforms source code to revitalize feature log levels based on the “interestingness” of the surrounding code. Built upon JGit and Mylyn, the approach is implemented as an Eclipse IDE plug-in and evaluated on 18 Java projects with ~3 million lines of code and ~4K log statements. Our tool successfully analyzes 99.26% of logging statements, increases log level distributions by ~20%, identifies logs manually modified with a recall of ~80% and a level-direction match rate of ~87%, and increases the focus of logs in bug fix contexts ~83% of the time. Moreover, pull (patch) requests were integrated into large and popular open-source projects. The results indicate that the approach is promising in assisting developers in evolving feature log levels.
Researchers
Publications
My and my research students‘ names are boldfaced, undergraduate students are italicized, and female students are underlined:
Yiming Tang, Allan Spektor, Raffi Khatchadourian, and Mehdi Bagherzadeh. A tool for rejuvenating feature logging levels via Git histories and degree of interest. In International Conference on Software Engineering: Companion Proceedings, ICSE-Companion ’22, pages 21–25. IEEE/ACM, IEEE, May 2022. (49/98; 50% acceptance rate). [ bib | DOI | arXiv | video | tool | slides | http ]
Yiming Tang, Allan Spektor, Raffi Khatchadourian, and Mehdi Bagherzadeh. Automated evolution of feature logging statement levels using Git histories and degree of interest. Science of Computer Programming, 214(C):102724, February 2022. Presented at the IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER ’22) journal-first track. [ bib | DOI | arXiv | video | data | tool | slides | http ]
Yiming Tang. Towards Automated Software Evolution of Data-intensive Applications. PhD thesis, City University of New York (CUNY) Graduate Center, 365 5th Ave, New York, NY 10016, June 2021. [ bib | http ]
Allan Spektor. Two techniques for automated logging statement evolution. Master’s thesis, City University of New York (CUNY) Hunter College, 695 Park Avenue, New York, NY 10065, July 2020. [ bib | http ]
Research Prototype
Study Data
Our dataset is hosted on Zenodo.
Presentations
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Introduction

The Java 8 Stream API sets forth a promising new programming model that incorporates functional-like, MapReduce-style features into a mainstream programming language. However, using streams efficiently may involve subtle considerations. For example, although streams enable developers to run their code in parallel with little alteration, it is often not obvious if such code runs more efficiently this way. In fact, under certain conditions, running stream code in parallel can be less efficient than running it sequentially. Moreover, it can be unclear if running sequential stream code in parallel is safe and interference-free due to possible lambda expression side-effects.
This project involves an automated refactoring approach that assists developers in writing optimal stream client code in a semantics-preserving fashion. The approach, based on a novel data ordering and typestate analysis, consists of refactorings that include preconditions and transformations for automatically determining when it is safe and possibly advantageous to convert a sequential stream to parallel and improve upon already parallel streams. The approach is implemented as a plug-in to the popular Eclipse IDE utilizing both WALA and SAFE.
Researchers
Publications
My and my research students‘ names appear in boldface. Undergraduate students appear in italics.
Raffi Khatchadourian, Yiming Tang, and Mehdi Bagherzadeh. Safe automated refactoring for intelligent parallelization of Java 8 streams. Science of Computer Programming, 195:102476, 2020. [ bib | DOI | http ]
Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. Safe automated refactoring for intelligent parallelization of Java 8 streams. Technical Report 544, City University of New York (CUNY) Hunter College, 695 Park Ave, New York, NY 10065 United States, July 2019. [ bib | http ]
Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. Safe automated refactoring for intelligent parallelization of Java 8 streams. In International Conference on Software Engineering, ICSE ’19, pages 619–630, Piscataway, NJ, USA, May 2019. ACM/IEEE, IEEE Press. (109/529; 20.6% acceptance rate). [ bib | DOI | tool | slides | http ]
Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. A tool for optimizing Java 8 stream software via automated refactoring. In International Working Conference on Source Code Analysis and Manipulation, SCAM ’18. IEEE, September 2018. (9/17; 53% acceptance rate). Best paper award. [ bib | tool | slides | http ]
Yiming Tang, Raffi Khatchadourian, Mehdi Bagherzadeh, and Syed Ahmed. Towards safe refactoring for intelligent parallelization of Java 8 streams. In International Conference on Software Engineering: Companion Proceeedings, ICSE ’18, pages 206–207, New York, NY, USA, May 2018. ACM/IEEE, ACM. [ bib | DOI | poster | http ]
Research Prototype
Our research prototype may be found on GitHub.
Supporting Repositories
- edu.cuny.hunter.streamrefactoring.annotations: Annotation library to manually specify program entry points.
Study Data
Subject Descriptions
| Subject | Version | Description |
|---|---|---|
| htm.java | 0.6.13 | Hierarchical Temporal Memory implementation in Java – an official Community-Driven Java port of the Numenta Platform for Intelligent Computing (NuPIC). |
| JacpFX | 2.1 | An API to create Rich Clients in MVC style with JavaFX, Spring (or other DI frameworks) and an Actor like component approach. |
| java-design-patterns | 1.12.0 (bc94d0f) | Design patterns implemented in Java. |
| jdk8-experiments | 3c7d717 | An personal repository for experimentation with the new JDK 8 features. |
| jetty.project | 9.4.8 | Eclipse Jetty – Web Container & Clients – supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more. |
| jOOQ | 3.10.4 | jOOQ is the best way to write SQL in Java. |
| koral | Scientific publishing with HTML. | |
| monads | 0.5 | Basic monads for Java. |
| retrolambda | 2.5.3 | Backport of Java 8’s lambda expressions to Java 7, 6 and 5. |
| streamql | 0.5.8 | A query tool for java.util.stream.Stream. |
| ThreeTen Extra | 1.3.2 | Provide additional date-time classes that complement those in JDK 8. |
Subject Source Code
The set of open-source Java projects packaged as Eclipse projects used for assessing our refactoring can be downloaded as an archive. Please refer to the included README.md file for building instructions and the LICENSE.md file for licensing information.
Raw Results
The data set consisting of the raw results produced during our study can be found on Zenodo.
Scripts used to produce the results can be found in our prototype implementation repository. htm_java.sh and jmh_profile.sh are the scripts used to execute the performance evaluation of htm.java and java-design-patterns, respectively. They assume that separate git branches are used to store the original source code and the refactored source code; these can be created using the above-mentioned patch files and git. mvn_check.sh, which also assumes the same git structure, is used to verify that the same test results exist before and after the refactoring. It can be easily adapted for projects that use Gradle.
Presentations
Awards & Nominations
Automatic Migration of Legacy Java Method Implementations to Interfaces
Java 8 is one of the largest upgrades to the popular language and framework in over a decade. It offers several new, key features that can help make programs easier to read, write, and maintain, especially in regards to collections. These features include Lambda Expressions, the Stream API, and enhanced interfaces, many of which help bridge the gap between functional and imperative programming paradigms and allow for succinct concurrency implementations. We investigate several open issues related to automatically migrating (refactoring) legacy Java software to use enhanced interfaces correctly, efficiently, and as completely as possible. Our goal is to help developers to maximally understand and adopt this new feature thus improving their software.
Automated Refactoring of Legacy Java Software to Enumerated Types
Introduction

Modern Java languages introduce several new features that offer significant improvements over older Java technology. In this project, we consider the new enum construct, which provides language support for enumerated types. Prior to recent Java languages, programmers needed to employ various patterns (e.g., the weak enum pattern) to compensate for the absence of enumerated types in Java. Unfortunately, these compensation patterns lack several highly-desirable properties of the enum construct, most notably, type safety. We present a novel fully-automated approach for transforming legacy Java code to use the new enumeration construct. This semantics-preserving approach increases type safety, produces code that is easier to comprehend, removes unnecessary complexity, and eliminates brittleness problems due to separate compilation. At the core of the proposed approach is an interprocedural type inference algorithm that tracks the flow of enumerated values. The algorithm was implemented as an open-source, publicly available Eclipse plug-in and evaluated experimentally on 17 large Java benchmarks. Our results indicate that analysis cost is practical and the algorithm can successfully refactor a substantial number of fields to enumerated types. This work is a significant step towards providing automated tool support for migrating legacy Java software to modern Java technologies.
Researchers
Publications
My and my research students‘ names appear in boldface. Undergraduate students appear in italics.
Raffi Khatchadourian. Automated refactoring of legacy Java software to enumerated types. Automated Software Engineering, 24(4):757–787, December 2017. [ bib | DOI | http ]
Raffi Khatchadourian and Benjamin Muskalla. Enumeration refactoring: A tool for automatically converting Java constants to enumerated types. In International Conference on Automated Software Engineering, ASE ’10, pages 181–182, New York, NY, USA, September 2010. IEEE/ACM. (18/45; 40% acceptance rate). [ bib | DOI | tool | slides | http ]
Raffi Khatchadourian, Jason Sawin, and Atanas Rountev. Automated refactoring of legacy Java software to enumerated types. In International Conference on Software Maintenance, ICSM 2007, pages 224–233. IEEE, October 2007. (46/214; 21% acceptance rate). [ bib | DOI | slides | http ]
Raffi Khatchadourian, Jason Sawin, and Atanas Rountev. Automated refactoring of legacy Java software to enumerated types. Technical Report OSU-CISRC-4/07-TR26, Ohio State University, April 2007. [ bib | .pdf ]
Research Prototype
Our research prototype may be found on GitHub.
Presentations
Pointcut Change Prediction
Pointcut fragility is a well-documented problem in Aspect-Oriented Programming; changes to the base-code can lead to join points incorrectly falling in or out of the scope of pointcuts. Deciding which pointcuts have broken because of changes made to the base-code is a daunting task, especially in large and complex systems. This project represents an automated approach that recommends a set of pointcuts that are likely to require modification due to a particular change in the base-code. Our hypothesis is that join points captured by a pointcut exhibit a varying degree of common structural characteristics on multiple levels. We use patterns describing such commonality to recommend pointcuts that have potentially broken to the developer, as well as point the developer in a direction in which the pointcut should be altered. We implemented our approach as an extension to the popular Mylyn Eclipse IDE plugin, which maintains focused contexts of entities relevant to the current task. We show that this approach is useful in revealing broken pointcuts by applying it to multiple versions of several open source projects and evaluating the accuracy of the recommendations produced against actual modifications made on these systems.
Porting the NetBeans Lambda Expression Refactoring to Eclipse
Introduction
Java 8 is one of the largest upgrades to the popular language and framework in over a decade. There are several new key features of Java 8 that can help make programs easier to read, write, and maintain. Java 8 comes with many features, especially related to collection libraries. These include such new features as Lambda Expressions, the Stream API, enhanced interfaces, and more.
While JDT Core/UI has incorporated many Java 8 quick fixes and refactorings, there are still many features left to be done. For example, NetBeans has a refactoring that converts loops to Lambda expressions. This project is for exploring the porting of the mechanism in NetBeans to Eclipse. These may be manifested as refactoring and/or “quick fixes.”
This project is open source. Please see the implementation page for download links.
People
Publications
CUNY researchers appear in bold. Undergraduate students appear in italics.
Md. Arefin and Raffi Khatchadourian. Porting the netbeans Java 8 enhanced for loop lambda expression refactoring to Eclipse. In Companion Proceedings of the 2015 ACM SIGPLAN International Conference on Systems, Programming, Languages and Applications: Software for Humanity, SPLASH Companion 2015, pages 58–59, New York, NY, USA, October 2015. ACM. [ bib | DOI | poster | http ]
Research Prototype
Our research prototype may be found on GitHub.
Pointcut Rejuvenation: Recovering Pointcut Expressions in Evolving Aspect-Oriented Software
Introduction
Pointcut fragility is a well-documented problem in Aspect-Oriented Programming; changes to the base-code can lead to join points incorrectly falling in or out of the scope of pointcuts. In this project, we use an automated approach that limits fragility problems by providing mechanical assistance in pointcut maintenance. The approach is based on harnessing arbitrarily deep structural commonalities between program elements corresponding to join points selected by a pointcut. The extracted patterns are then applied to later versions to offer suggestions of new join points that may require inclusion. To illustrate that the motivation behind our proposal is well-founded, we first empirically establish that join points captured by a single pointcut typically portray a significant amount of unique structural commonality by analyzing patterns extracted from 23 AspectJ programs. Then, we demonstrate the usefulness of our technique by rejuvenating pointcuts in multiple versions of 3 of these programs. The results show that our parameterized heuristic algorithm was able to automatically infer new join points in subsequent versions with an average recall of 0.93. Moreover, these join points appeared, on average, in the top 4th percentile of the suggestions, indicating that the results were precise.
Researchers
| Name | Affiliation |
|---|---|
| Raffi Khatchadourian | City University of New York (CUNY) Hunter College |
| Phil Greenwood | Relative Insight |
| Awais Rashid | Universit of Bristol |
| Guoqing Xu | UCLA |
Publications
My and my research students‘ names are boldfaced, undergraduate students are italicized, and female students are underlined:
Raffi Khatchadourian, Phil Greenwood, Awais Rashid, and Guoqing Xu. Pointcut rejuvenation: Recovering pointcut expressions in evolving aspect-oriented software. IEEE Transactions on Software Engineering, 38(3):642–657, May 2012. [ bib | DOI | http ]
Raffi Khatchadourian, Phil Greenwood, Awais Rashid, and Guoqing Xu. Pointcut rejuvenation: Recovering pointcut expressions in evolving aspect-oriented software. In International Conference on Automated Software Engineering, ASE ’09, pages 575–579, Washington, DC, USA, November 2009. IEEE/ACM. (71/222; 32% acceptance rate). [ bib | DOI | slides | http ]
Raffi Khatchadourian and Awais Rashid. Rejuvenate pointcut: A tool for pointcut expression recovery in evolving aspect-oriented software. In International Working Conference on Source Code Analysis and Manipulation, SCAM ’08, pages 261–262. IEEE, September 2008. [ bib | DOI | tool | slides | http ]
Raffi Khatchadourian, Phil Greenwood, Awais Rashid, and Guoqing Xu. Pointcut rejuvenation: Recovering pointcut expressions in evolving aspect-oriented software. Technical Report COMP-001-2008, Lancaster University, Lancaster, UK, August 2008. Revised March 2009, May 2009. [ bib | http ]
Research Prototype
Our research prototype may be found on GitHub.
Study Data
Subject Descriptions
| Subject | Versions | Description |
|---|---|---|
| Jakarta Cactus | 6 | A simple test framework for unit testing server-side java code. |
| Contract4J | 5 | A tool that supports Design by Contract (DbC) programming in Java 5. |
| AJHotDraw | 1 | An aspect-oriented refactoring of JHotDraw, a relatively large and well-designed open source Java framework for technical and structured 2D graphics. |
| Ants | 1 | An AspectJ implementation of a simulator for the problem given in the 2004 ICFP Programming Contest. |
| Bean | 1 | An example from the AspectJ documentation which shows how to turn a class into a JavaBean. |
| DCM | 1 | A computation of the dynamic coupling metric of Hassoun et al. |
| Figure | 1 | The classic figure editor example. |
| Glassbox | 1 | A troubleshooting agent for Java applications that automatically diagnoses common problems. |
| LawOfDemeter | 1 | A Law of Demeter (LoD) checker written in AspectJ. |
| MySQL Connector/J | 1 | A native Java driver that converts JDBC calls into the network protocol used by the MySQL database. |
| NullCheck | 1 | Checks for the anti-pattern of methods that return null. |
| N-Version | 1 | An AspectJ library for fault tolerance (1/2). |
| Quicksort | 1 | An AspectJ implementation of the classic algorithm. |
| RacerAJ | 1 | An algorithm for dynamic race detection in Java and AspectJ programs. |
| RecoveryCache | 1 | An AspectJ library for fault tolerance (2/2). |
| Spacewar | 1 | An example AspectJ project that ships with the Eclipse AJDT. |
| StarJ-Pool | 1 | A widely used AspectJ benchmark from the literature. |
| Telecom | 1 | A simple telecommunications example in AspectJ. |
| Tetris | 1 | An AspectJ implementation of the classic game. |
| TollSystem | 1 | An AspectJ implementation of a subset of real-world toll system requirements. |
| Tracing | 1 | A simple tracing example that ships with the Eclipse AJDT. |
| MobileMedia (formally MobilePhoto) | 7 | A software product line for applications that manipulate photo, music, and video on mobile devices. |
| HealthWatcher | 10 | A web-based application that provides various medical-related support, used in a wide variety of empirical studies. |


