Source-linked AI summary

DEAR: A Novel Deep Learning-based Approach for Automated Program Repair

Yi Li, Shaohua Wang, Tien N. Nguyen

arXiv:2205.01859v1cs.SE

TL;DR

Existing deep-learning APR models are limited in fixing general defects that require dependent changes across multiple statements or hunks. DEAR combines fault localization with compositional, context-aware subtree repair for such fixes. It reports more fixed bugs than the best-performing deep-learning baseline on each of three datasets.

  • Problem

    Existing deep-learning APR approaches are limited in fixing defects that require dependent changes to multiple statements or hunks.

    Source: §1 · p. 1
  • Method

    DEAR combines spectrum-based fault localization, deep learning, and data-flow analysis with compositional, context-aware subtree transformation learning for joint multi-statement and multi-hunk repair.

    Source: §1 · pp. 1–2
  • Results

    DEAR fixes 31% (+11), 5.6% (+41), and 9.3% (+31) more bugs than CURE on Defects4J, BigFix, and CPatMiner, respectively, using Top-1 patches.

    Source: §1 · p. 2
  • Takeaways & Limitations

    The paper reports that DEAR achieves results comparable and complementary to top pattern-based APR tools.

    Source: §1 · p. 2

    In the Figure 9 example, sequence-based baselines do not derive the structural changes well, DLFix's one-statement-at-a-time repair does not work, and no pattern-based fixing template is available.

    Source: Illustrative Example · p. 11

Abstract

from arXiv · show

The existing deep learning (DL)-based automated program repair (APR) models are limited in fixing general software defects. % We present {\tool}, a DL-based approach that supports fixing for the general bugs that require dependent changes at once to one or multiple consecutive statements in one or multiple hunks of code. % We first design a novel fault localization (FL) technique for multi-hunk, multi-statement fixes that combines traditional spectrum-based (SB) FL with deep learning and data-flow analysis. It takes the buggy statements returned by the SBFL model, detects the buggy hunks to be fixed at once, and expands a buggy statement $s$ in a hunk to include other suspicious statements around $s$. We design a two-tier, tree-based LSTM model that incorporates cycle training and uses a divide-and-conquer strategy to learn proper code transformations for fixing multiple statements in the suitable fixing context consisting of surrounding subtrees. We conducted several experiments to evaluate {\tool} on three datasets: Defects4J (395 bugs), BigFix (+26k bugs), and CPatMiner (+44k bugs). On Defects4J dataset, {\tool} outperforms the baselines from 42\%--683\% in terms of the number of auto-fixed bugs with only the top-1 patches. On BigFix dataset, it fixes 31--145 more bugs than existing DL-based APR models with the top-1 patches. On CPatMiner dataset, among 667 fixed bugs, there are 169 (25.3\%) multi-hunk/multi-statement bugs. {\tool} fixes 71 and 164 more bugs, including 52 and 61 more multi-hunk/multi-statement bugs, than the state-of-the-art, DL-based APR models.

1 INTRODUCTION

DEAR targets dependent multi-statement and multi-hunk defects that statement-by-statement deep-learning repair approaches are limited in fixing. It combines fault localization, compositional subtree transformations, and context-aware learning, and reports gains over deep-learning baselines across three datasets.

1 INTRODUCTION

  • Existing deep-learning repair approaches fix individual statements, limiting their ability to repair dependent changes spanning multiple statements or hunks.When one statement depends on another buggy statement, treating the latter as correct can make an individual-statement repair inaccurate.Source: §1 · p. 1
  • DEAR combines spectrum-based fault localization with deep learning and data-flow analysis to identify statements and hunks that need joint repair.It learns fixing-together relationships among suspicious statements and expands a seed statement to include other suspicious consecutive statements.Source: §1 · pp. 1–2
  • A divide-and-conquer approach uses fine-grained AST mappings to learn local subtree transformations for multi-hunk, multi-statement fixes.The mappings help avoid incorrect alignments between buggy and fixed code.Source: §1 · p. 2
  • DEAR's two-layer tree-based LSTM uses attention and cycle training to learn fixing context and then context-weighted subtree transformations.During training, the context for one buggy subtree includes the fixed versions of other buggy subtrees rather than their buggy versions.Source: §1 · p. 2
  • DEAR fixes 31% (+11), 5.6% (+41), and 9.3% (+31) more bugs than CURE on Defects4J, BigFix, and CPatMiner, respectively, using Top-1 patches.It uses seven times fewer training parameters on average; on CPatMiner, 169 of its 667 fixed bugs are multi-hunk/multi-statement bugs.Source: §1 · p. 2
  • DEAR reports comparable and complementary results to top pattern-based APR tools, including fixing 12 of 47 Defects4J bugs that the top pattern-based tool could not fix.Seven of those 12 fixes were multi-hunk/multi-statement bugs.Source: §1 · p. 2

B. Advanced DL-based APR Techniques:

DEAR advances deep-learning APR for general bugs by supporting dependent multi-hunk and multi-statement fixes. Its contributions combine fault localization, compositional repair, an enhanced LSTM model, and empirical evaluation against other APR approaches.

B. Advanced DL-based APR Techniques:

2 MOTIVATION

The motivating example illustrates why a repair may require coordinated changes across buggy statements and why surrounding context must reflect other fixes. DEAR addresses this with buggy-hunk detection, compositional subtree learning, context-aware transformation models, and a staged repair process.

2.1 Motivating Example

  • In the verifyUserInfo example, the fix jointly adds a null-handling branch, capitalizes the UID, and hashes the password; changing statements individually does not fix the bug.The DL-based tools described fix one statement at a time, while the example's dependent changes must occur together.Source: §2.1 · pp. 2–3
  • The example's repair transforms multiple buggy AST subtrees into multiple fixed statements, motivating a divide-and-conquer treatment of subtree changes.Source: §2.1 · p. 3

2.2 Key Ideas

  • DEAR uses SBFL candidates to detect hunks that need joint repair, then expands each hunk to include consecutive suspicious statements; data dependencies can add a statement to the joint fix.In the example, a dependency through retrieve_password brings line 10 into the fix after SBFL flags line 5.Source: §2.2 · p. 3
  • Fine-grained AST change mappings support divide-and-conquer learning of local transformations and reduce incorrect alignments between buggy and fixed code.The example's changed statements are grouped into mappings that can be learned as separate subtree transformations.Source: §2.2 · p. 3
  • DEAR composes transformations for multiple buggy subtrees using an enhanced tree-based LSTM with attention and cycle training.Its two layers learn context and subtree transformation, and the learned context weights the transformation.Source: §2.2 · p. 3

2.3 Approach Overview

  • Training uses before- and after-fix source parsed into ASTs to train context and tree-transformation models; the context model's weights adjust the transformation model's output.The context-learning procedure uses fixed versions of other buggy subtrees to build the context for each subtree.Source: §2.3 · pp. 3–4
  • At repair time, DEAR starts with buggy source and tests, localizes and groups suspicious statements, and expands them with RNN classification and data-flow analysis.For detected subtrees, context and transformation models produce a candidate patch, which is processed with grammatical rules and program analysis, then reranked and validated with tests.Source: §2.3 · p. 4

3 TRAINING PROCESS

DEAR trains on paired buggy and fixed AST subtrees, building context representations and learning subtree transformations. Its tree-based LSTM uses attention and cycle training to learn fixes in surrounding-code context.

3.1 Pairing Buggy and Fixed Subtrees

  • CPatMiner-derived subtree pairs map buggy updates and deletions to their fixed counterparts, with deleted subtrees paired to empty trees and inserted subtrees paired to their parent or an empty tree.The training pairs are derived from source code before and after fixes, which may involve multiple methods.Source: §3.1 · p. 4

3.2 Context Building

  • For each pair, DEAR vectorizes ASTs, summarizes the buggy and fixed subtrees, and builds before- and after-fix method contexts for context-model training.Other buggy subtrees are replaced by their fixed versions when constructing context; the resulting contexts feed the encoder and decoder, while subtree vectors later weight transformation learning.Source: §3.2 · p. 4

3.3 Context Learning via Tree-based LSTM with Attention Layer and Cycle Training

  • The context model uses a three-layer encoder-decoder-attention architecture with Child-Sum Tree-based LSTMs and cycle training to emphasize likely input-output mappings.Cycle training addresses one-to-many and many-to-one fix mappings by emphasizing the input and its most likely output; forward and backward mappings are trained with cycle-consistency loss.Source: §3.3 · p. 5

3.4 Tree Transformation Learning

  • Tree transformation learning applies the same attention-based, cycle-trained tree LSTM to each buggy S-subtree, using context vectors as weights for node-vector cross-products.The resulting buggy and fixed subtrees serve as the model's input and output for learning transformations.Source: §3.4 · p. 5

4 FIXING PROCESS

DEAR groups suspicious statements into jointly fixed hunks, expands them to consecutive buggy statements, then generates context-aware fixes and filters candidate patches.

4.1 Fixing-together Hunk Detection Algorithm

  • The fine-tuned BERT groups suspicious hunks for joint repair using statement-pair scores, while groups containing the most suspicious statement are ranked first.SBFL supplies suspicious statements, which are grouped into hunks; the average BERT score across statement pairs is compared with a threshold.Source: §4.1 · pp. 5–6

Key Idea.

  • Data-flow dependencies can add a statement predicted non-buggy to the hunk, and expansion stops in each direction at a non-buggy statement without a dependency.The RNN-classified buggy statements and statements dependent on the seed determine the consecutive hunk.Source: Key Idea · p. 6

4.2 Multiple-Statement Expansion Algorithm

  • The expansion algorithm examines five statements on either side of a seed statement and uses an RNN to classify candidates before data-flow adjustment.The implementation sets N=5; expansion returns a consecutive buggy hunk.Source: Key Idea · p. 6

Training.

  • The GRU-based RNN is trained on buggy and non-buggy statements, consuming GloVe token vectors and labeling each time-step statement 1 or 0.The previous time-step output is also fed into the GRU.Source: Training · pp. 6–7, Prediction · p. 7

4.3 Tree-based Code Repair

  • For each identified buggy AST subtree, DEAR predicts its context and transformation, using context-derived weights to adjust candidate fixed subtrees.When one buggy subtree contains another, only the larger subtree needs repair; token-similarity scores rank candidate patches.Source: §4.3 · p. 7

4.4 Post-processing

  • Post-processing filters invalid candidates by alpha-renaming, syntax, and name checks, then uses beam search, re-ranking, and test validation.Candidates are checked from the top downward until one passes all test cases.Source: §4.4 · p. 7

5 EMPIRICAL EVALUATION

The evaluation compares DEAR with deep-learning and pattern-based repair tools across three datasets, examining bug-fixing performance, sensitivity, runtime, and model size.

5.1 Research Questions

  • The five research questions compare DEAR with deep-learning and pattern-based APR, assess sensitivity, and examine runtime and training parameters.The comparisons cover Defects4J and large datasets, alongside sensitivity analysis.Source: §5.1 · pp. 7–8

5.2 Data Collection

  • The evaluation uses Defects4J with 395 bugs, BigFix with over 26,000 bugs, and CPatMiner with over 44,000 bugs.The experiments ran on an eight-core CPU workstation with one GTX Titan GPU.Source: §5.2 · p. 8

5.3 Experimental Methodology

  • On Defects4J, the study compares six DL-based models and evaluates correct and plausible patches among top-ranked candidates.The Defects4J experiments also use Ochiai fault localization and a five-hour limit for patch generation and validation.Source: §5.3 · p. 8
  • For BigFix and CPatMiner, the evaluation uses 80/10/10 splits and cross-dataset tests, supplying actual bug locations because the datasets lack test cases.Developer fixes serve as ground truth; the DL baselines process statements individually rather than distinguishing hunks.Source: §5.3 · p. 8
  • The study also tests four factors with leave-one-out analyses and measures training and fixing time and model parameters.The first three sensitivity factors are tested on Defects4J, while data splitting is tested on CPatMiner.Source: §5.3 · p. 8

6 EMPIRICAL RESULTS

On Defects4J, DEAR fixes more bugs than the compared DL-based tools, including bugs requiring coordinated multi-hunk or multi-statement changes.

6.1 RQ1. Comparison Results with DL-based APR Models on Defects4J

  • 47 bugs were auto-fixed by DEAR on Defects4J, the highest count among the compared models; it also generated 91 plausible patches.DEAR fixed 11 more bugs than CURE, a 31% relative improvement, and fixed 18 bugs missed by the combined baselines.Source: Table 1 · p. 9, §6.1 · p. 9
  • 14 multi-hunk bugs were fixed by DEAR that DLFix, CoCoNuT, and CURE could not fix.Across bug Types 2–5, DEAR fixed 18 multi-hunk or multi-statement bugs, 38.3% of its 47 fixed bugs.Source: Table 2 · p. 9, §6.1 · p. 9
  • With correct fixing locations, DEAR fixed 53 bugs versus 44, 40, and 48 for the compared baselines.Of DEAR's 53 fixes, 20 were multi-hunk or multi-statement, compared with 7, 5, and 10 for CoCoNuT, DLFix, and CURE.Source: Table 3 · p. 9, §6.1 · p. 9
  • DEAR is fully data-driven and does not require the predefined fixing patterns used by pattern-based APR models.The paper characterizes DEAR as supporting dependent multi-hunk or multi-statement fixes.Source: §6.1 · p. 9

6.2 RQ2. Comparison Results with DL-based APR Models on Large Datasets

DEAR fixes more bugs than DL-based baselines on BigFix and CPatMiner, and reaches comparable bug counts to leading pattern-based tools while handling additional multi-statement cases.

6.2 RQ2. Comparison Results with DL-based APR Models on Large Datasets

  • 40–322 more bugs were fixed on CPatMiner and 31–145 more on BigFix than by DL-based baselines with top-1 patches; DEAR also outperformed them cross-dataset.DEAR fixed 15.1% of 4,415 CPatMiner bugs and 14.1% of 2,594 BigFix bugs with top-1 patches.Source: §6.2 · p. 9
  • Among 667 fixed bugs, DEAR fixed 169 multi-hunk or multi-statement bugs (Types 2–5, 25.33% of total) and fixed 71, 164, and 41 more bugs than CoCoNuT, DLFix, and CURE, respectively.Its multi-hunk/multi-statement margins were 52, 61, and 40 bugs over CoCoNuT, DLFix, and CURE, respectively.Source: §6.2 · pp. 9–10

6.3 RQ3. Comparison Results with Pattern-based APR Models

  • DEAR performed at the same bug-count level as pattern-based tools Hercules and Tbar.It fixed 7 multi/mix-statement bugs Hercules missed, including non-replicated bugs; it fixed 9 fewer one-statement bugs of Types 1 and 3 than Hercules because of incorrect fixes.Source: Table 7 · p. 10, §6.3 · p. 10, Table 8 · p. 10
  • DEAR fixed 15 more multi-hunk or multi-statement bugs than Tbar, which repairs one statement at a time.The three Type 2 bugs Tbar fixed had independent statement fixes.Source: §6.3 · p. 10

6.4 RQ4. Sensitivity Analysis

DEAR’s sensitivity checks show that hunk detection and statement expansion recover different multi-hunk and multi-statement bugs, while attention and cycle training and more training data also improve results.

6.4 RQ4. Sensitivity Analysis

  • With hunk detection, DEAR fixes 14 more multi-hunk bugs, but two fewer Type-1 bugs, than without hunk detection.The comparison identifies hunk detection as useful for bugs requiring dependent fixes across multiple hunks.Source: §6.4.1 · p. 10

6.4.1 Impact of Fixing-together Hunk Detection.

  • Expansion fixes 7 more multi-statement bugs but 3 fewer Type-3 and Type-1 bugs than without expansion.The reported cause of the losses is incorrect expansion of a single-statement bug into a multi-statement hunk.Source: §6.4.2 · p. 10

6.4.2 Impact of Multi-Statement Expansion.

  • Without hunk detection, DEAR misses all 14 multi-hunk bugs; without expansion, it misses all 7 multi-statement bugs.Among the 14 hunk-detection fixes, 11 are Type-3, while all 7 expansion fixes are multi-statement bugs that existing DL-based APR approaches cannot fix.Source: §6.4.2 · p. 10

6.4.3 Impact of Tree-based LSTM model with Attention and Cycle

  • Removing attention and cycle training reduces Defects4J fixes by 7 bugs, a 17.5% decrease across all bug types.The comparison removes both mechanisms together.Source: §6.4.3 · p. 10

6.4.4 Impact of Training Data’s Size.

  • With 70%/30% training data, DEAR achieves 11.7% top-1, above DLFix’s 11.4% and SequenceR’s 7.7% with 90%/10% splits.The paper reports higher DEAR accuracy with more training data; Table 10 presents the training-data-size evaluation.Source: §6.4.4 · pp. 10–11, Table 10 · p. 11

6.5 RQ5. Time Complexity and Parameters

DEAR uses fewer training parameters than CURE while outperforming it, and the evaluation reports its runtime and scope. The paper also notes limits in bug types and fix sizes.

6.5 RQ5. Time Complexity and Parameters

  • Prediction takes 2.4–3.1 seconds per candidate on CPatMiner, 3.6–4.2 seconds on BigFix, and 2.1 seconds on Defects4J.Training takes +22 hours on CPatMiner and 18–19 hours on BigFix; validating all tests for a fix takes 2–20 minutes.Source: §6.5 · p. 11
  • DEAR uses 7 and 7.3 times fewer training parameters than CURE on CPatMiner and BigFix, respectively, while fixing more bugs.On CPatMiner, DEAR and CURE require 0.39M and 3.1M parameters; on BigFix, they require 0.42M and 3.5M.Source: §6.5 · p. 11
  • The evaluation uses Java; pattern-based APR comparisons are limited to Defects4J because those tools require test-case datasets.The authors report trying to re-implement the pattern-based baselines and CURE for a fair comparison.Source: Threats to Validity · p. 11

Threats to Validity.

  • DEAR’s example fixes two buggy hunks with multiple statements, using an existing method variable to compose the fix.The passage contrasts this with sequence-based baselines’ structural-change difficulty and DLFix’s one-statement-at-a-time approach.Source: Illustrative Example · p. 11

Illustrative Example.

  • DEAR is limited to failing-test bugs and cannot generate fixes with several new statements or arbitrarily large dependent changes.Other stated limitations include rare or out-of-vocabulary names, incorrect hunk expansion, and a current focus on Java.Source: Limitations · p. 11

7 RELATED WORK

Related work spans deep learning and pattern-based APR approaches. The paper distinguishes DEAR’s multi-hunk, multi-statement target from existing DL tools’ individual-statement repairs.

Deep Learning-based APR approaches

  • Deep-learning APR approaches use similarity, syntax rules, neural machine translation, code structures, trees, or code-aware language models to suggest fixes.The paper characterizes existing DL-based APR models as ineffective for multi-hunk, multi-statement bugs because they fix individual statements at a time.Source: §7 · p. 11

Pattern-based APR approaches

  • Pattern-based APR mines fixes from prior patches or templates, while search-based systems include semantic repair and patch-representation approaches.The authors did not compare Angelix because CapGen outperforms it, and report that DEAR fixes 42 bugs versus ARJA’s 18 on the same four Defects4J projects.Source: §7 · p. 11

8 CONCLUSION

DEAR combines a multi-hunk fault-localization technique, compositional repair, and an attention- and cycle-trained two-layer LSTM. It outperforms DL-based APR baselines across Defects4J, BigFix, and CPatMiner, including on multi-hunk/multi-statement bugs.

8 CONCLUSION

  • DEAR contributes multi-hunk fault localization, divide-and-conquer compositional repair, and a two-layer LSTM enhanced with attention and cycle training.Its fault localization combines spectrum-based analysis, deep learning, and data-flow analysis.Source: §8 · p. 11
  • On CPatMiner, DEAR fixes 40–52 more multi-hunk/multi-statement bugs than the baselines.On Defects4J, it outperforms DL-based APR baselines by 42%–683% in fixed bugs; on BigFix, it fixes 31–145 more bugs with top-1 patches.Source: §8 · pp. 11–12
Loading 2205.01859v1…