Source-linked AI summary

Identifying Patch Correctness in Test-Based Program Repair

Yingfei Xiong, Xinyuan Liu, Muhan Zeng, Lu Zhang, Gang Huang

arXiv:1706.09120v3cs.SE

TL;DR

Weak real-world test suites let incorrect patches pass, limiting the reliability and precision of test-based program repair. The paper uses PATCH-SIM and TEST-SIM to generate and classify tests through execution-behavior similarity, then heuristically identify incorrect patches. On 139 patches, it filtered 56.3% of incorrect patches without blocking any correct patches.

  • Problem

    Weak test suites allow many incorrect patches to pass, forcing manual verification and limiting the precision and usability of test-based repair systems.

  • Method

    The approach generates new test inputs, classifies them by similarity to existing passing or failing executions, and compares original-versus-patched execution behavior using PATCH-SIM and TEST-SIM.

  • Results

    56.3% of incorrect patches were filtered out without losing any correct patches on a dataset of 139 patches.

  • Takeaways & Limitations

    Behavior similarity is a promising way to address the oracle problem and improve the precision of program repair approaches.

  • Takeaways & Limitations

    Generalization to future repair tools with characteristics different from current tools remains unknown, and dataset patch removal may introduce selection bias.

Abstract

from arXiv · show

Test-based automatic program repair has attracted a lot of attention in recent years. However, the test suites in practice are often too weak to guarantee correctness and existing approaches often generate a large number of incorrect patches. To reduce the number of incorrect patches generated, we propose a novel approach that heuristically determines the correctness of the generated patches. The core idea is to exploit the behavior similarity of test case executions. The passing tests on original and patched programs are likely to behave similarly while the failing tests on original and patched programs are likely to behave differently. Also, if two tests exhibit similar runtime behavior, the two tests are likely to have the same test results. Based on these observations, we generate new test inputs to enhance the test suites and use their behavior similarity to determine patch correctness. Our approach is evaluated on a dataset consisting of 139 patches generated from existing program repair systems including jGenProg, Nopol, jKali, ACS and HDRepair. Our approach successfully prevented 56.3\% of the incorrect patches to be generated, without blocking any correct patches.

1 INTRODUCTION

Test-based repair systems can produce plausible but incorrect patches because real-world test suites are weak. The paper proposes PATCH-SIM and TEST-SIM to heuristically classify patches using execution behavior, filtering incorrect patches while retaining correct ones.

  • Motivation: Weak test suites allow patched programs to pass all tests while remaining faulty, making plausible patches unreliable indicators of correctness.The paper defines a plausible patch as one passing the test suite, but a correct patch must fix and only fix the bug.
  • Motivation: Low precision forces developers to manually verify many incorrect patches and can reduce their performance compared with receiving no patch.The authors therefore prioritize improving precision, even at the risk of losing some correct patches.
  • Approach: PATCH-SIM and TEST-SIM use behavior similarity to provide indicators of patch correctness and classify generated patches without knowing the full oracle.PATCH-SIM compares executions before and after patching; TEST-SIM relates newly generated tests to existing passing or failing tests.
  • Approach: The approach generates new test inputs, classifies them by comparison with existing tests, and compares original-versus-patched executions across both original and generated tests.These steps operationalize the two behavior-similarity observations in an automated classification process.
  • Evaluation: 56.3% of incorrect patches were filtered out without losing any correct patches on a dataset of 139 patches.The patches came from jGenProg, Nopol, jKali, HDRepair, and ACS; the authors report improved precision with limited negative impact on recall.

2 RELATED WORK

Related work addresses test-based repair, patch classification, patch ranking, and the oracle problem through search, statistical, constraint-based, deterministic, heuristic, and similarity-based techniques. The paper positions its dynamic behavior-based approach as complementary to several existing methods, while identifying extensions as future work.

  • Test-based Program Repair: Test-based repair treats repair as a search problem over patch spaces, using predefined templates to locate patches that satisfy tests.Existing repair strategies include search algorithms, statistical models, and constraint solving.
  • Test-based Program Repair: Weak test suites remain a challenge across patch-generation methods and can lead to incorrect patches.The paper reports that its approach can augment existing repair approaches to raise their precision.
  • Patch Classification: Existing patch-classification methods use perfect oracles, inherent oracles, static anti-patterns, or behavioral impact, whereas this approach mainly relies on dynamic information.The authors state that their approach and anti-patterns can potentially be combined.
  • Patch Ranking: Patch ranking orders patches by likelihood, but classification additionally requires a threshold that may differ from defect to defect.A perfect ranking method therefore does not necessarily yield perfect classification.
  • Approaches to the Oracle Problem: Applying invariant mining to patch classification remains future work because its effect on correctness identification is still unknown.The passage describes invariant mining as potentially useful when a full correct program is available.
  • Patch Classification: Independent test suites and human developers can assess patch quality but are unavailable for automatically improving repair precision.The paper distinguishes these evaluation resources from automated classification methods.

3 PATCH CORRECTNESS AND BEHAVIOR SIMILARITY

The paper motivates patch correctness heuristics through two observations: correct patches tend to preserve passing-test behavior and change failing-test behavior, while similar test executions tend to share results. Examples show how PATCH-SIM and TEST-SIM address weaknesses in oracles and inputs.

  • Definitions: A patch is correct only if it fixes and only fixes the bug, whereas a plausible patch merely passes all tests.The discussion assumes one fault so a failing execution triggers that fault and produces incorrect output.
  • Weak Oracles and PATCH-SIM: PATCH-SIM expects similar executions before and after patching for passing tests, but different executions for failing tests.In the Chart-15 example, the patched program skips draw on a passing test, creating a significant behavioral difference that identifies the patch as incorrect.
  • Weak Inputs and TEST-SIM: The Lang-39 patch evades existing tests because their inputs happen to produce correct outputs despite the patch blocking the whole loop.PATCH-SIM is insufficient here because passing-test behavior remains almost unchanged while failing-test behavior changes substantially.
  • Weak Inputs and TEST-SIM: TEST-SIM classifies new test inputs by comparing their executions with existing passing and failing tests.Inputs whose executions resemble failing tests are likely to produce incorrect output, while those resembling passing tests are likely to produce correct output.
  • Measuring Execution Similarity: Execution similarity is measured using complete-path spectrum, the sequence of executed statement IDs during a program execution.Prior studies cited by the paper found spectra useful for distinguishing correct and failing executions, with CPS among the best-performing spectra.
  • Multiple Faults: With multiple faults, the heuristics treat the identified faults as one fault and treat the remaining faults as correct-program behavior.The authors state that the preceding reasoning still applies under this treatment.

4 APPROACH

The approach generates and classifies additional tests, then compares execution behavior before and after patching to assess patch correctness. It measures execution similarity with normalized longest-common-subsequence distances and applies separate test and patch classification rules.

  • 4.1 Overview: The pipeline generates test inputs, measures execution distances, classifies generated tests, and classifies patches.Its five components span test generation, distance measurement, and result classification.
  • 4.1 Overview: Generated tests are compared with original tests and classified as passing or failing using TEST-SIM.Tests with difficult classifications may be discarded.
  • 4.3 Distance Measurement: Execution distance compares complete-path spectra using normalized longest common subsequence distance between two sequences.The resulting distance is normalized to a value between 0 and 1.
  • 4.3 Distance Measurement: The method restricts runtime traces to statements executed within the calling context of patched methods to filter unrelated behavior.This focuses comparisons on executions relevant to the patched methods.
  • 4.4.1 Test Classifier: The test classifier compares a generated test’s nearest distances to passing and failing tests, assigning passing, failing, or discarded labels.When no passing test exists, it uses threshold Kt against failing tests under a normal-input assumption.
  • 4.4.2 Patch Classifier: The patch classifier requires small behavior changes for passing tests and greater average behavior change for failing tests.It uses maximum distance for passing tests and average distance for failing tests.

5 IMPLEMENTATION

The approach is implemented as a Java patch-classification tool that takes a program, test suite, and patch and reports whether the patch is correct. Randoop generates tests, while location-focused generators are identified as potentially more suitable but are not used.

  • 5 IMPLEMENTATION: The implementation classifies a Java patch as correct or incorrect given the program and its test suite.The tool accepts a Java program, a test suite, and a patch as input.
  • 5 IMPLEMENTATION: Randoop is used as the random test-generation tool in the implementation.The generated tests are intended to cover patched methods.
  • 5 IMPLEMENTATION: Location-focused symbolic-execution or search-based generators may be more suitable, but the implementation does not use them because they target fewer tests.The paper gives Evosuite’s maximum of three test cases per buggy program as an example.

6 EVALUATION

The evaluation uses labeled automatic-repair patches from Defects4J and tests reliability, effectiveness, comparisons, generation strategies, parameters, and classification errors. Unsupported patches are removed, and the experiments include separate baselines and repeated random-generation runs.

  • 6 EVALUATION: The evaluation examines similarity reliability, patch-correctness identification, competing approaches, test generation, parameter settings, and false classifications.Additional analysis considers developer patches separately.
  • 6.2 Dataset: Patches unsupported by the implementation, mainly because Randoop generated no tests, are removed; this excludes Closure and Mockito patches.The resulting dataset therefore does not cover every Defects4J project.
  • 6 EVALUATION: The evaluation dataset contains 139 automatic-repair patches: 110 incorrect and 29 correct.Patches come from six repair tools and target defects in Defects4J.
  • 6.3 Experiment Setup: The study evaluates PATCH-SIM with patched-versus-unpatched execution distances and TEST-SIM with distances between tests and their results.RQ2 compares classifications with patch-correctness labels.
  • 6.3 Experiment Setup: Existing comparisons include anti-patterns, Opad, AST-based syntactic distance, and complete-path-spectrum semantic distance.The syntactic and semantic methods produce ranked patch lists whose thresholds are assessed for separating correct and incorrect patches.
  • 6.4 Test Generation: The no-generation strategy provides a baseline, while repeated Randoop runs assess the contribution and randomness of generated tests.Repeated runs are evaluated on 50 randomly selected patches and repeated five times.

6.4 Result of RQ1: Reliability of Heuristics

PATCH-SIM and TEST-SIM hold in general: execution distances distinguish passing from failing tests across patches, while short test distances predict matching test results.

  • PATCH-SIM: For correct patches, failing-test execution distances are 9.5 times those of passing tests, compared with 1.32 times for incorrect patches.This supports using PATCH-SIM to distinguish correct and incorrect patches.
  • TEST-SIM: When two tests have a short execution distance, they are more likely to have the same test results.With longer distances, different test results become more likely.
  • TEST-SIM: TEST-SIM therefore provides an execution-based signal for predicting whether tests trigger the same fault or are both normal executions.The heuristic relies on similar executions being associated with similar test results.

6.5 Result of RQ2: Overall Effectiveness

Across tools and projects, the approach filtered many incorrect plausible patches without filtering correct ones in the evaluated dataset, though its runtime can reach 30 minutes.

  • Overall effectiveness: 62 of 110 incorrect plausible patches were filtered out, while no correct patch was filtered out.The same pattern appeared in evaluations organized by tool and by project.
  • Overall effectiveness: Performance was similar across different tools and projects, suggesting potential generalizability across the evaluated tool and project types.The evidence concerns the tools and projects represented in the dataset.
  • Limitations: Correct patches can theoretically be filtered when they substantially change a passing test's control flow while preserving its result.The paper gives new algorithms or different API calls as examples of such changes.
  • Cost: Patch correctness determination took 5 to 10 minutes in most cases, with some patches requiring up to 30 minutes.Most time was spent generating test inputs and recording runtime traces.

6.6 Result of RQ3: Comparing with Others

Compared with alternative similarity and oracle-based approaches, the proposed method better separates correct from incorrect patches, although syntactic and semantic distances may still rank patches within individual defects.

  • Comparison with other approaches: Anti-patterns filtered 27 incorrect and 1 correct patch, whereas the proposed approach filtered more incorrect patches without filtering correct ones.The two approaches also overlap on 13 incorrect patches, suggesting possible combination.
  • Comparison with other approaches: Opad filtered no incorrect patches with 20 tests and only 3 with up to 50 tests, indicating limited effect from inherent oracles in this setting.The comparison used the same generated test inputs as the proposed approach.
  • Syntactic distance: Excluding 56.3% of incorrect patches by syntactic distance would require excluding 66.7% of correct patches.Correct and incorrect patches appeared across all syntactic-distance intervals.
  • Semantic distance: Excluding 56.3% of incorrect patches by semantic distance would require excluding 43.3% of correct patches.Semantic distance was better than syntactic distance for this purpose but remained significantly worse than the proposed approach.
  • Interpretation: Syntactic and semantic distances may rank correct patches higher for individual defects despite lacking a group-wide correctness threshold.The paper distinguishes patch ranking from directly determining correctness across defects.
  • Test generation: Removing generated test inputs filtered out 8 fewer incorrect patches while still filtering no correct patches.PATCH-SIM alone was effective, but test generation and TEST-SIM further improved performance.
  • Randomness: Across five repetitions, randomness changed results for only 3 of 50 selected patches, with at most a one-patch difference between best and worst cases.The reported impact of randomness was limited.

6.8 Result of RQ5: Parameters

The approach is relatively insensitive to parameter choices, but misclassification is mainly associated with weak test suites, unsatisfying generated tests, and limitations in the classification formula. It also excludes a small fraction of correct developer patches when their control flow or execution behavior changes substantially.

  • Parameter Sensitivity: Different Kt and Kp values have limited impact, and a broad parameter range can achieve the best overall performance.Both parameters range from 0 to 1; the results are reported in Tables 7 and 8.
  • Causes of Wrong Results: 21 of 48 analyzed wrong classifications involved test suites with only one failing test covering the patched method.Without passing tests, classification relies on the Kt threshold, making suitable passing tests difficult to obtain.
  • Causes of Wrong Results: 27 of 48 wrong classifications involved test generation that failed to cover the patched method or expose incorrect behavior.Nine cases overlapped with the weak-test-suite category, and stronger test generation could potentially improve identification.
  • Causes of Wrong Results: 8 of 48 wrong classifications were caused by large behavior changes in failing-test executions inflating the average distance.Generating more failing test cases may reduce the influence of such outlier distances.
  • Developer Patches: 8.25% of correct developer patches were classified as incorrect because substantial control-flow or CPS changes affected passing-test behavior.The authors interpret this as evidence that human patches are more complex than patches generated by current automated techniques.

7 THREATS TO VALIDITY AND LIMITATIONS

The evaluation is subject to internal, external, and construct-validity threats, including patch selection, uncertain generalization, manual correctness judgments, and unexplored formula choices.

  • Internal Validity: Discarding patches whose correctness was undetermined or unsupported by the infrastructure may introduce selection bias.The authors consider the threat limited because the removed patches were few and unlikely to change the overall results substantially.
  • External Validity: The approach may perform differently on future repair tools whose characteristics differ substantially from current tools.The study sampled major categories of repair tools, but generalization beyond them remains uncertain.
  • Construct Validity: Manual patch-correctness evaluation may produce classification errors.Difficult cases were discussed by the first two authors to reach a mutual decision.
  • Design Scope: The paper does not explore all possible execution-distance formulas, spectra, or statistical classification methods.These alternative design choices are left for future work.

8 CONCLUSION

The paper proposes determining patch correctness from similarities between program executions and reports that this approach can filter many incorrect patches without excluding correct ones.

  • Conclusion: 56.3% of incorrect patches were filtered without losing any correct patches.The authors conclude that behavior similarity is a promising way to address the oracle problem.
Loading 1706.09120v3…