Introduction
Locating the exact line of code responsible for a software bug is a critical but labor-intensive task in software maintenance. Traditional Spectrum-Based Bug Localization (SBBL) relies on dynamic test coverage data, which often falters when test suites are inadequate or have low coverage. This paper introduces EnSpec, a hybrid approach that enhances SBBL by incorporating the "naturalness" of code, measured through statistical language models. By identifying code that appears statistically "surprising" or "unnatural," EnSpec provides a robust orthogonal signal for pinpointing defects at a fine-grained level.
The EnSpec Methodology
EnSpec operates through a four-stage pipeline that integrates static code analysis with dynamic execution data to produce a ranked list of suspicious lines.
- Entropy Generation: Using a statistical language model (specifically a $gram model), EnSpec calculates the "entropy" of every line. High entropy indicates that a line is statistically rare given its context, suggesting it may be "unnatural" and thus more likely to be buggy. These scores are normalized by the line's AST syntax type.
- Feature Extraction: The system extracts 25 distinct SBBL suspiciousness scores (e.g., Ochiai, Tarantula) based on the program's test suite execution.
- Model Training: A Random Forest classifier is trained on these features. To address the scarcity of buggy lines, the model is trained using evolutionary bug data mined from version control histories.
- Ranking: Finally, EnSpec produces a ranked list of suspicious lines for developer inspection based on a hybrid suspiciousness score.
Evaluation and Insights
The researchers evaluated EnSpec using the Defects4J (Java) and ManyBugs (C) benchmarks, covering over 500 reproducible bugs. A central finding is that buggy code consistently exhibits higher entropy than healthy code, containing unusual token sequences that language models find improbable. In the Random Forest models, "Average Entropy" emerged as the most significant feature for prediction, even outperforming classic metrics like Ochiai. This suggests that entropy serves as an effective "tie-breaker" when multiple lines appear equally suspicious based on test results alone.
Experimental Results
EnSpec demonstrates significant improvements over standard SBBL methods across both Java and C projects, proving that the "naturalness" of code is a universal property across programming languages.
On average, EnSpec achieved a 6.6% gain in the Area Under the Cost-Effectiveness Curve (AUCEC). Its advantages are most pronounced in "low-budget" scenarios: when inspecting only the top 20% of suspicious lines, EnSpec successfully located 98.63% of bugs, compared to 80.08% for SBBL alone—a relative improvement of over 33%.
Conclusion
By leveraging the statistical properties of programming languages, EnSpec overcomes the limitations of test-suite-dependent bug localization. While currently focused on modification bugs, future work aims to address "bugs of omission" and utilize more advanced semantic models to further refine the entropy signal for automated program repair tools.
Summary updated