TL;DR
This paper introduces CURE, a novel approach to automatic program repair (APR) that leverages code-specific knowledge within neural machine translation (NMT) models. By pre-training a programming language model and employing a code-aware search strategy, CURE significantly outperforms existing APR techniques in fixing software bugs.
What Problem Does This Paper Address?
Automatic Program Repair (APR) aims to automatically fix bugs in software, reducing the burden of manual debugging. While Neural Machine Translation (NMT) has shown promise in this area, existing NMT-based APR methods face two major limitations:
- Limited Search Space: The correct fix is often not present in the set of patches the NMT model can generate.
- Ineffective Search Strategy: The search process for a fix ignores crucial software knowledge, such as strict syntax rules, leading to many uncompilable or incorrect patches.
These limitations cause NMT-based APR to underperform traditional template-based methods. The authors aim to bridge this gap by developing an NMT approach that is "code-aware."
Methods
CURE introduces three core novelties:
- Programming Language (PL) Model Pre-training: CURE first pre-trains a GPT model on a massive corpus of open-source Java code. This "PL model" learns the syntax and common patterns of developer-written code, providing a strong foundation for the subsequent APR task.
- Code-Aware Search Strategy: Instead of a generic beam search, CURE employs a specialized strategy:
- Valid Identifier Check: It uses static analysis to identify valid identifiers in the code's scope and forces the search to only consider sequences containing these valid tokens, preventing syntactically incorrect patches.
- Length Control: It penalizes generated patches that are significantly shorter or longer than the original buggy code, as most correct fixes tend to be similar in length.
- Subword Tokenization: CURE uses Byte Pair Encoding (BPE) to tokenize code. This reduces the vocabulary size and effectively handles out-of-vocabulary (OOV) tokens, which are common in code and can hinder NMT models.
These components are integrated into an NMT architecture (CoNuT) and fine-tuned for the APR task.
Datasets
- PL Training Data: 4.04 million Java methods extracted from 1,700 open-source projects (versions before 2006 to avoid data leakage).
- Patch Training Data: The dataset from CoCoNuT [19], consisting of 2.72 million training instances (buggy lines, context, and correct fixes) extracted from 45,180 Java projects.
- Evaluation Benchmarks:
- Defects4J (v1.4.0)
- QuixBugs
Key Insights and Ideas
- Code has unique characteristics: Unlike natural language, source code has strict syntax and semantics that generic NMT models struggle with. CURE's "code-awareness" is key to overcoming this.
- Pre-training on code matters: A dedicated PL model trained on a large code corpus significantly improves the NMT model's understanding of code syntax and developer practices.
- Syntax and length are crucial search heuristics: Simply maximizing token probability isn't enough for APR. Enforcing syntactic validity and guiding the search towards patches of appropriate length dramatically improves the quality of generated fixes.
- Subword tokenization is vital for code: The OOV problem is a significant hurdle in code-based NMT. BPE effectively mitigates this, expanding the search space to include more correct fixes.
Key Results
- State-of-the-art performance: CURE correctly fixes 57 bugs in Defects4J and 26 bugs in QuixBugs, outperforming all existing APR techniques on both benchmarks.
- Fixes unique bugs: CURE fixes bugs that previous state-of-the-art tools (both NMT-based and pattern-based) could not, including bugs requiring specific transformations or handling of out-of-context identifiers.
- Higher compilable patch rate: CURE generates significantly more compilable patches in its top candidate lists compared to other NMT-based approaches, demonstrating the effectiveness of its code-aware search.
- Improved patch rank: The code-aware search strategy also improves the ranking of correct patches, making them easier to find.
Limitations and Future Work
- Single-hunk bugs: CURE, like most APR techniques, is primarily designed for single-hunk bugs (where the fix involves a single code segment).
- Generalizability: While the approach is generalizable to other programming languages by updating the PL parser, it was only evaluated on Java.
- Training data accuracy: There's a potential risk of inaccuracies in the automatically extracted training data, although efforts were made to ensure quality.
- Future Work: The authors suggest evaluating CURE on more recent benchmarks and exploring its application to other programming languages. They also highlight the potential of code-awareness for other deep learning tasks in software engineering.
Summary updated