Automatic Repair of Buggy If Conditions and Missing Preconditions with SMT

Automatic Repair of Buggy If Conditions and Missing Preconditions with   SMT
Notice: This research summary and analysis were automatically generated using AI technology. For absolute accuracy, please refer to the [Original Paper Viewer] below or the Original ArXiv Source.

We present Nopol, an approach for automatically repairing buggy if conditions and missing preconditions. As input, it takes a program and a test suite which contains passing test cases modeling the expected behavior of the program and at least one failing test case embodying the bug to be repaired. It consists of collecting data from multiple instrumented test suite executions, transforming this data into a Satisfiability Modulo Theory (SMT) problem, and translating the SMT result – if there exists one – into a source code patch. Nopol repairs object oriented code and allows the patches to contain nullness checks as well as specific method calls.


💡 Research Summary

The paper introduces Nopol, an automated repair tool targeting two common classes of bugs in Java programs: incorrect if‑condition expressions and missing preconditions. Nopol operates in a test‑suite based setting, requiring at least one failing test case that exhibits the bug and a set of passing tests that define the intended behavior. The repair pipeline consists of four main phases: (1) angelic fix localization, (2) runtime trace collection, (3) SMT encoding, and (4) patch synthesis.

In the first phase, Nopol explores potential repair locations by manipulating program execution during the failing test. For each if‑condition encountered, it forces the condition to evaluate either true or false. If this forced evaluation makes the failing test pass, the pair (location, forced Boolean value) is recorded as a candidate fix and its corresponding oracle. For missing preconditions, the tool forces the execution to skip a statement; if skipping leads to a passing test, the oracle is set to false, indicating that a precondition evaluating to false should be inserted before the statement. Candidate locations are prioritized using the Ochiai suspiciousness metric, so the most likely faulty conditions are examined first, reducing the search space dramatically (2 × n for n executed if‑conditions, or the number of executed statements for preconditions).

During the second phase, Nopol runs the entire test suite while instrumenting the program to capture the local state at each candidate location. The captured state includes primitive values (integers, booleans) and object‑oriented information such as nullness and the results of a limited set of method calls (e.g., size(), isEmpty()).

The third phase translates the collected data and the oracle into a Satisfiability Modulo Theories (SMT) problem. The SMT formula enforces that, for all passing test executions, the synthesized condition must evaluate identically to the original one, while for the failing test it must evaluate to the oracle value (true/false). The encoding supports Boolean operators, relational operators, null checks, and the aforementioned method calls, allowing the synthesis of expressions that combine these elements. An off‑the‑shelf SMT solver (e.g., Z3) is then invoked to check satisfiability.

If the solver returns a model, the fourth phase extracts the concrete expression from the model and generates a source‑code patch. The patch either replaces the original if‑condition or inserts a new precondition before the targeted statement. Example patches include adding a null check and a size comparison: if (l != null && l.size() > 0) { compute(l); }.

The authors evaluate Nopol on the Apache Commons Math library (≈5 000 lines of code, 352 JUnit tests) and on two real‑world bugs. In all cases Nopol successfully produced correct patches that match the functionality of manually written fixes. Repair times ranged from a few seconds to a few minutes, demonstrating practical feasibility. The study also highlights limitations: the current encoding cannot handle arbitrary method calls or complex object state, which may cause synthesis failure for more intricate bugs.

Overall, Nopol contributes a novel combination of angelic value manipulation for simultaneous fix‑location and oracle discovery, and SMT‑based program synthesis for generating concrete patches. By avoiding heavyweight symbolic execution and supporting essential object‑oriented features such as nullness checks, Nopol advances the state of the art in automated program repair for condition‑related defects.


Comments & Academic Discussion

Loading comments...

Leave a Comment