Introduction
Refactoring is a critical practice in software maintenance, aimed at improving internal code structure without altering external behavior. While its benefits are widely accepted, quantifying the actual impact of refactoring efforts remains challenging. This study investigates Self-Admitted Refactorings (SARs)—commits where developers explicitly state their intent to refactor in the commit message. By analyzing these "self-labeled" improvements, we can determine if explicit intent correlates with measurable gains in code quality.
Methodology
The researchers employed a multi-stage pipeline to identify and analyze SARs:
- Identification: Commit messages were scanned for 22 specific "refactoring roots" (e.g., Extract, Rename, Move).
- Verification: Manual inspection and the Ref-Finder tool were used to confirm that structural changes actually occurred, filtering out false positives.
- Measurement: The static analysis tool PMD measured code smells—indicators of potential design flaws—before and after each commit.
- Comparison: SAR commits were compared against a control group of non-SAR commits to evaluate the relative effectiveness of explicit refactoring intent.
Dataset and Context
The study focused on two prominent Java-based Open Source Software (OSS) projects: Fastjson (by Alibaba) and Junit4 (by Apache). Fastjson is a large-scale JSON processor (~111k LOC), while Junit4 is a smaller, mature testing framework (~26k LOC).
Key Results
Effectiveness of Refactoring Intent
The study found that explicit intent is a strong predictor of quality improvement. In approximately 70% of SAR cases, the number of code smells either decreased or remained stable.
As shown in the table above, SAR commits in Fastjson were significantly more effective at preventing new smells compared to non-SAR commits (70.25% vs 37.19%). In Junit4, however, the difference was less pronounced, suggesting that project maturity and contributor discipline may influence the outcomes of refactoring efforts.
Targeted Code Smells
Developers appear to prioritize specific types of technical debt during refactoring. The most frequently addressed smell in both projects was DataflowAnomalyAnalysis, which relates to how variables are used and assigned.
The data indicates that while refactoring often reduces smells (negative DNCS), it can occasionally introduce new ones. For instance, in Fastjson, DataflowAnomalyAnalysis saw a net reduction of 131 smells, whereas in Junit4, it actually increased by 18.
Discussion and Limitations
While SARs generally improve code quality, they are not infallible; roughly 30% of self-admitted refactorings resulted in an increased code smell count. This suggests that structural changes, even when well-intentioned, can introduce new complexities.
The study's findings are limited by its focus on two Java projects and its reliance on PMD for smell detection. Furthermore, it only captures "admitted" refactorings, potentially overlooking "silent" refactorings that occur without explicit commit labels. Future research should explore these silent changes and expand the dataset to include diverse languages and proprietary environments.
Conclusion
Self-Admitted Refactorings serve as a reliable signal for quality-improving intent. While not a guaranteed fix for technical debt, SARs are generally more effective than standard commits at maintaining or improving code health, particularly in larger, rapidly evolving projects like Fastjson.
Summary updated