NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Predicting Patch Correctness Based on the Similarity of Failing Test Cases

Haoye Tian, Yinghua Li, Weiguo Pian, Abdoul Kader Kaboré, Kui Liu, Andrew Habib, Jacques Klein, Tegawendé F. Bissyandé

TL;DR

This paper introduces BATS, a novel unsupervised learning approach to predict the correctness of automatically generated software patches. BATS leverages the intuition that similar failing test cases should correspond to similar patch fixes, outperforming existing methods and offering a complementary approach to state-of-the-art techniques.

What Problem Does This Paper Address?

Automated Program Repair (APR) systems generate patches to fix bugs, but a major hurdle is determining if these patches are actually correct. APR systems often produce "plausible" patches that pass existing test suites but don't generalize to fix the underlying issue, leading to "patch overfitting." This necessitates manual verification by developers, which is time-consuming. Existing methods for predicting patch correctness have limitations: dynamic approaches are slow, static approaches require extensive feature engineering, and many machine learning methods need large labeled datasets. This paper addresses the challenge of efficiently and accurately identifying correct patches without relying on extensive manual labeling or computationally expensive test execution.

Methods

The core of BATS is its hypothesis: "similar failing test cases should require similar patches." To implement this, BATS uses a multi-step process:

  1. Pre-processing: Test cases and patches are tokenized, breaking down code into meaningful units. For patches, only changed lines (added/removed) are considered, preserving the '+' and '-' markers.
  2. Embedding: State-of-the-art deep learning models like code2vec (for test cases) and CC2Vec or BERT (for patches) are used to convert code and patches into high-dimensional vector representations that capture semantic similarities.
  3. Finding Similar Test Cases: For a given buggy program and its failing test cases, BATS searches a historical dataset of bugs to find test cases that are semantically similar to the current failing tests.
  4. Mapping to Patches: The identified similar historical test cases are mapped to their corresponding developer-written "correct" patches.
  5. Similarity-based Prediction: BATS computes the similarity between the APR-generated patch and the average embedding of the historical correct patches associated with similar failing test cases. If this similarity exceeds a predefined threshold, the APR patch is predicted as correct; otherwise, it's deemed incorrect.

Datasets

The primary dataset used is Defects4J, a widely used benchmark for software engineering research, containing Java programs with known bugs and developer-written fixes. The authors also augmented this with datasets from previous studies on APR systems and collected patches from various APR tools. In total, they used a dataset of 1,278 plausible patches, including 205 developer-written (correct) patches and 1,073 APR-generated (potentially incorrect) patches.

Key Insights and Ideas

  • The "Similar Test, Similar Patch" Heuristic: The central idea that failing test cases can act as a proxy for the type of fix needed is a powerful and intuitive concept. This paper provides empirical evidence supporting this heuristic.
  • Unsupervised Approach: BATS's unsupervised nature is a significant advantage, as it doesn't require large, manually labeled datasets of correct/incorrect patches, which are expensive to create.
  • Complementarity: BATS isn't presented as a silver bullet but as a valuable tool that can enhance existing methods. It can be combined with supervised classifiers and dynamic analysis tools to improve overall performance.
  • Asymmetry in Hypothesis: The study found that while similar test cases lead to similar patches, the reverse is not always true: similar patches don't necessarily address similar failing test cases. This suggests that the directionality of the hypothesis is important.

Key Results

  • Performance: BATS achieved an AUC (Area Under Curve) between 0.557 and 0.718 and a recall (for identifying correct patches) between 0.562 and 0.854.
  • Comparison: BATS outperformed state-of-the-art static and dynamic approaches, including Tian et al.'s deep learning method and PATCH-SIM.
  • Enhancement: When combined with a supervised classifier, BATS improved +Recall by up to 5 percentage points. When complementing PATCH-SIM, it improved overall performance.
  • Efficiency: BATS is significantly faster than dynamic approaches like PATCH-SIM, with an average prediction time of ~0.3 seconds per patch.

Limitations and Future Work

  • Availability of Similar Test Cases: BATS's performance is dependent on the availability of similar historical test cases in the search space. If few similar test cases exist, its effectiveness can be limited.
  • Dataset Size: While the paper presents a large dataset, the availability of historical examples can still be a constraint for certain projects or bugs.
  • Embedding Models: The use of pre-trained embedding models might not always be perfectly adapted to specific code domains. Future work could involve retraining or fine-tuning these models.
  • Closure Project Anomaly: The Closure project's unique string-based test specification format posed challenges for the code2vec model, requiring its exclusion from some analyses. Future work could explore specialized learners for such formats.
  • Bug Report Integration: The authors suggest exploring bug reports as an additional source of information for understanding bug categories and required fixes.
  • Cross-Project Search: While BATS can search across projects, further investigation into cross-project and cross-language search for similar code could be beneficial.

Summary updated

BibTeX
@article{tian2022predicting,
  author = {Haoye Tian and Yinghua Li and Weiguo Pian and Abdoul Kader Kaboré and Kui Liu and Andrew Habib and Jacques Klein and Tegawendé F. Bissyandé},
  title = {{Predicting Patch Correctness Based on the Similarity of Failing Test Cases}},
  journal = {ACM Trans. Softw. Eng. Methodol.},
  year = {2022},
  url = {https://openreview.net/forum?id=QMWzqciwWb},
}
Figure