Abstract
Automated program repair is a crucial task for improving the efficiency of software developers. Recently, neural-based techniques have demonstrated significant promise in generating correct patches for buggy code snippets. However, most existing approaches arbitrarily treat the buggy context without any analysis to capture the semantic relationship between the buggy statement and its context. Additionally, we observe that existing neural models may output an unaltered patch consistent with the input buggy code snippet, which fails to be the correct human-written one for fixing the given bug. To address the aforementioned limitations, we present in this paper a novel neural program repair framework called REPEATNPR, which adapts the general pre-trained language model for fixing single-line Java bugs. We make the first attempt to use program slicing to extract contextual information directly related to the given buggy statement as repair ingredients from the corresponding program dependence graph and eliminate unaltered patches using an intuitive but effective filter mechanism. We demonstrate the effectiveness of REPEATNPR on five benchmarks when compared with state-of-the-art baselines.
Introduction
Automated Program Repair (APR) aims to fix software bugs without human intervention, significantly reducing the burden on developers. Neural Program Repair (NPR) has recently emerged as a powerful paradigm, treating bug fixing as a machine translation task where buggy code is "translated" into a correct patch. Despite its potential, NPR faces two critical challenges: the inclusion of irrelevant code context and the tendency of models to generate "unaltered patches"—outputs that are identical to the buggy input.
Problem Statement: Contextual Noise and the Unaltered Patch Trap
Existing NPR models often ingest arbitrary windows of code surrounding a bug. This approach introduces "contextual noise," where irrelevant statements distract the model, or misses distant but semantically vital dependencies. Furthermore, because buggy and fixed code are often nearly identical, models frequently fall into a local optimum, predicting an unaltered patch that fails to resolve the bug.
Methodology: The REPEATNPR Framework
To overcome these hurdles, we propose REPEATNPR (pRogram dEPEndence Analysis with a filTer mechanism). The framework optimizes the repair process through three integrated stages.
1. Dependency-Based Slicing
Instead of using a fixed text window, REPEATNPR utilizes Program Dependence Graphs (PDGs) to perform "program slicing." This process identifies every statement that either affects the buggy line's data flow or controls its execution. By focusing on these "repair ingredients," the model captures semantic relationships rather than just textual proximity.
2. CodeT5 Backbone
The framework leverages CodeT5, a state-of-the-art pre-trained encoder-decoder model designed for code. We fine-tune CodeT5 on the sliced context to learn complex bug-fixing patterns from a large-scale corpus of bug-fixing pairs.
3. Effective Filter Mechanism
To address the unaltered patch problem, REPEATNPR employs a filtering strategy. If the primary model generates a patch identical to the input, the system discards it and invokes a secondary NPR model (e.g., SEQUENCER). This ensemble approach ensures the system continues searching for a valid fix rather than returning a redundant output.
Evaluation and Results
We evaluated REPEATNPR against ten state-of-the-art baselines across five standard Java benchmarks: BFP, Bugs.jar, Defects4J, Bears, and QuixBugs.
- Superior Accuracy: REPEATNPR outperformed all baselines in "exact match" patches. On the BFP benchmark, it produced 15.9% more correct patches than the standard CodeT5. On the Bears benchmark, it achieved a remarkable 62.5% improvement.
- Ablation Success: Experiments confirmed that both program slicing and the filter mechanism are essential. Removing either component led to a significant drop in repair performance.
- Complexity Handling: REPEATNPR showed particular strength in "Insert" and "Replace" operations, which are traditionally difficult for NMT-based models as they require synthesizing new logic.
Conclusion
REPEATNPR demonstrates that the quality of context is more important than quantity in neural program repair. By combining semantic-aware program slicing with a robust filtering mechanism, we significantly improve the state-of-the-art for single-line Java bug fixes. Future work will focus on extending this approach to multi-line bugs and incorporating project-specific API knowledge to further enhance repair capabilities.
Summary updated