Gamma: Revisiting Template-Based Automated Program Repair Via Mask Prediction

Quanjun Zhang, Chunrong Fang, Tongke Zhang, Bowen Yu, Weisong Sun, Zhenyu Chen

Abstract

Automated Program Repair (APR) has traditionally been divided between template-based methods, which offer structural reliability but lack flexibility, and learning-based methods, which offer flexibility but struggle with correctness. This paper introduces GAMMA, a novel APR tool that bridges this gap by transforming bug-fixing into a mask prediction task. By combining human-defined fix templates with the predictive power of pre-trained language models (PLMs), GAMMA achieves state-of-the-art performance, repairing 82 real-world bugs in the Defects4J benchmark and outperforming existing approaches by over 20%.

Introduction

Software maintenance is a resource-intensive process, making Automated Program Repair (APR) a critical area of research. Existing APR techniques generally fall into two categories:

  1. Template-based APR: These tools apply predefined fix patterns. While they produce high-quality patches, they are often limited by the "donor code" problem—the inability to find the necessary variables or methods if they are not present in the local file.
  2. Learning-based APR: These tools use Neural Machine Translation (NMT) to generate fixes. While more flexible, they frequently suffer from "hallucinations" or generate syntactically incorrect code.

GAMMA (Mask Prediction-based Repair) addresses these issues by using templates as structural "guardrails" and leveraging PLMs to fill in the specific details (the "donor code") through a fill-in-the-blank approach.

Methodology: The GAMMA Workflow

GAMMA operates through a four-stage pipeline designed to minimize the search space while maximizing the "intuition" of modern AI models.

  1. Fault Localization: Standard tools identify suspicious code lines.
  2. Template Selection: GAMMA selects a fix template (e.g., Mutating Operators, Null Pointer Checks) based on the Abstract Syntax Tree (AST) of the buggy code.
  3. Mask Template Definition: Instead of searching for local donor code, GAMMA replaces the variable parts of the template with <mask1>, <mask2>, etc.
  4. Patch Generation via PLMs: The masked code, context, and original buggy line are fed into a PLM (like UniXcoder). The model performs a "cloze task" to predict the missing tokens.
  5. Validation: Candidate patches are validated against test suites to ensure they resolve the bug without introducing regressions.

Evaluation and Results

The researchers evaluated GAMMA on the Defects4J (v1.2 and v2.0) and QuixBugs benchmarks.

Key Performance Metrics

GAMMA correctly repaired 82 bugs on Defects4J v1.2, representing a 20.59% improvement over TBar and a 26.15% improvement over Recoder. Notably, it achieved a high precision rate, with 81.19% of plausible patches being manually verified as correct.

As shown in the figure above, GAMMA fixed 14 unique bugs that were not resolved by any other tool in the comparison set, highlighting its ability to explore fix spaces that traditional template-based or pure learning-based tools miss.

Discussion and Conclusion

GAMMA demonstrates that PLMs have internalized enough "code intuition" during pre-training to solve the donor code problem without requiring local search or extensive fine-tuning. By providing the original buggy line as a hint, the model can better infer developer intent.

However, limitations remain. GAMMA is currently optimized for single-location bugs and is still dependent on the breadth of its template library. Future work will focus on extending this mask-prediction paradigm to multi-line fixes and more complex architectural bugs.

Summary updated

BibTeX
@inproceedings{zhang2023gamma,
  author = {Quanjun Zhang and Chunrong Fang and Tongke Zhang and Bowen Yu and Weisong Sun and Zhenyu Chen},
  title = {{Gamma: Revisiting Template-Based Automated Program Repair Via Mask Prediction}},
  booktitle = {ASE},
  year = {2023},
  doi = {10.1109/ase56229.2023.00063},
}
Figure