Automated program repair (APR) is often considered the "holy grail" of software engineering—tools that can automatically identify and fix bugs. Traditionally, these tools rely on test suites or formal assertions to define correct behavior. However, writing comprehensive tests is time-consuming, and sparse test suites often lead to "overfitting," where a tool produces a patch that passes the tests but fails to fix the underlying logic. This paper introduces JDial, a tool that shifts the paradigm from test-based repair to Direct State Manipulation (DSM).
The Problem with Test-Based Repair
Most APR tools face two significant hurdles:
- Under-specification: A simple input/output pair (e.g., "input 5 should result in 10") provides no information about intermediate logic. A synthesizer might "cheat" by adding a hardcoded conditional rather than fixing a loop error.
- High Effort: Creating a robust test suite is difficult, particularly for novice programmers or for code that is still in development.
JDial addresses these issues by allowing programmers to interact directly with a buggy execution trace. Instead of writing a new test, a user identifies a point where a variable's value is incorrect and simply "types over it" with the correct value.
The JDial Workflow
JDial transforms a user's manual state correction into a formal synthesis problem. The system architecture, illustrated below, involves several key components that bridge the gap between a user's intent and a functional code fix.
Sketch-Based Synthesis
JDial utilizes the Sketch synthesizer. It generates a "sketched" version of the buggy program where constants and operators are replaced with "holes" (??). The goal is to find values for these holes that satisfy the user's state manipulation and any existing test cases.
The Alignment Challenge
A unique challenge in trace-based repair is "alignment." If a repair changes a loop's iteration count, the specific location the user manipulated might shift. JDial solves this by introducing an existential "visit time" variable, allowing the synthesizer to determine which iteration of a loop corresponds to the user's correction.
Distance Metrics and Optimization
To ensure the generated fixes are logical and minimal, JDial employs two cost functions:
- Syntactic Distance: Prefers fixes that modify the fewest lines of code.
- Semantic Distance: Prefers fixes that minimize changes to the overall execution trace.
To handle larger programs, JDial uses program slicing to ignore code segments that do not affect the manipulated variable, significantly reducing the search space.
Key Insights and Results
The researchers evaluated JDial on 17 Java programs, including introductory programming assignments and complex multi-loop benchmarks like bubbleSort.
- Information Density: A single state manipulation is often more informative than multiple test cases. By specifying where and how a state is wrong, the search space for a fix is narrowed much faster.
- Superior Accuracy: In head-to-head comparisons with Qlose (a state-of-the-art test-based tool), JDial generated the intended repair in 66% of cases where Qlose failed. While Qlose often produced trivial fixes (like modifying return statements), JDial consistently identified logical errors in loops and assignments.
- Efficiency: Slicing optimizations allowed JDial to find repairs for programs like
maxMinin under a second, whereas non-optimized versions timed out.
Conclusion and Future Work
JDial demonstrates that direct state manipulation is a powerful alternative to traditional test-based repair, especially for fixing logical errors in small-to-medium-sized programs. While the tool currently assumes a "perfect" user who provides correct values, future work will explore how to handle "noisy" or incorrect user manipulations and how to scale these techniques to massive, real-world codebases through automated fault localization.
Summary updated