What really changes when developers intend to improve their source code: a commit-level study of static metric value and static analysis warning changes

Alexander Trautsch, Johannes Erbel, Steffen Herbold, Jens Grabowski

Introduction

Software metrics, such as cyclomatic complexity (McCC) and logical lines of code (LLOC), are frequently employed as proxies for internal code quality. Static analysis tools utilize these metrics to flag potential maintenance issues, yet the relationship between a developer's intent to improve code and the resulting changes in these metrics remains under-explored. This study investigates whether developer efforts to "clean up" or "fix" code actually result in improved static metrics, revealing a complex dynamic between maintenance types and code quality.

Methodology

The research utilized a multi-stage approach to analyze the alignment between developer intent and metric changes across a large-scale dataset:

  1. Manual Ground Truth: Researchers manually inspected 2,533 commits from 54 Java open-source projects within the Apache Software Foundation (via the SmartSHARK ecosystem). Commits were categorized into three types: Perfective (refactoring for better structure/readability), Corrective (bug fixes), and Other (new features or administrative changes).
  2. Automated Classification: To scale the analysis, the manual dataset was used to fine-tune seBERT, a BERT-based language model pre-trained on software engineering corpora. This model achieved an F1-score of 0.80, allowing for the automated classification of 125,482 commits.
  3. Metric Analysis: For each commit, 14 static source code metrics were calculated using OpenStaticAnalyzer for files before and after the change. Statistical significance was determined using the Mann-Whitney U test, with Cliff’s delta used to measure effect sizes.

Key Insights and Results

The Bug-Fix Paradox

A primary finding of the study is the "bug-fix paradox." While developers intend to improve the system by fixing bugs (corrective maintenance), these changes often lead to an increase in complexity and size. Fixing a bug frequently involves adding conditional logic or handling edge cases, which degrades internal quality metrics like McCC and LLOC, even as it improves external software behavior.

Effectiveness of Refactoring

In contrast, perfective maintenance (refactoring) generally succeeds in reducing complexity, coupling, and size. However, the study noted that these improvements do not extend to "comment density" or "clone coverage," suggesting that developers prioritize structural logic over documentation or code duplication during cleanup phases.

Targeting "Low-Hanging Fruit"

The analysis revealed a bias in where developers apply perfective maintenance. Refactoring efforts tend to target files that are already relatively simple (median McCC ~19). Conversely, corrective maintenance is more common in highly complex files (median McCC ~33). This suggests that the most complex components of a system are often avoided during proactive cleanup and only touched when a failure occurs.

Tooling and Thresholds

The study suggests that current static analysis tool thresholds may be set too high to be effective early-warning systems. For instance, while the tool PMD defaults to a warning at a cyclomatic complexity of 80, the researchers found that 50% of files requiring bug fixes had a complexity of only 34 or higher.

Conclusion

The findings highlight a disconnect between the goals of corrective maintenance and the resulting internal code quality. While refactoring effectively reduces complexity, bug fixes tend to increase it, particularly in already complex files. Future static analysis tools should consider being context-aware, potentially lowering warning thresholds for files frequently targeted by bug fixes to encourage "perfective" interventions before technical debt becomes unmanageable.

Summary updated

BibTeX
@article{trautsch2023what,
  author = {Alexander Trautsch and Johannes Erbel and Steffen Herbold and Jens Grabowski},
  title = {{What really changes when developers intend to improve their source code: a commit-level study of static metric value and static analysis warning changes}},
  journal = {Empir. Softw. eng},
  year = {2023},
  doi = {10.1007/s10664-022-10257-9},
}
Figure