Beep: Fine-grained Fix Localization by Learning to Predict Buggy Code Elements

Shangwen Wang, Kui Liu, Bo Lin, Li Li, Jacques Klein, Xiaoguang Mao, Tegawendé F. BissyandéarXiv 2021

Abstract

Beep (Buggy codE Elements Predictor) is a deep learning framework that shifts software fault localization from coarse-grained lines to fine-grained code tokens. By accurately predicting both the specific buggy element and the required repair action (e.g., UPDATE, DELETE), Beep enables automated repair pipelines to generate patches with a 100% correctness ratio, effectively eliminating the "overfitting" problem where patches pass tests but remain logically incorrect.

Introduction

Automated Program Repair (APR) tools aim to fix bugs without human intervention. However, they rely on Fault Localization (FL) to find the bug first. Most existing FL techniques are "coarse-grained," identifying only the buggy method or line.

This creates two major hurdles:

  1. Search Space Explosion: If a tool only knows a line is buggy, it must guess which token to change and how to change it, leading to an astronomical number of potential fix attempts.
  2. Patch Overfitting: Because the search space is so large, APR tools often find "plausible" patches—changes that trick the test suite into passing but don't actually fix the underlying logic.

The authors argue that for APR to be industrial-grade, we need Fix Localization: pinpointing the exact token and the specific operation (Insert, Delete, Update) needed to fix it.

The Beep Framework

Beep addresses these challenges by learning to predict the "Operation Path"—a triplet consisting of the Buggy Token, its AST Position, and the Change Action.

Overview of the Beep pipeline, from data pre-processing to off-line training and inference.

Methodology and Architecture

Beep uses a specialized neural network architecture designed to understand the structural context of code. Instead of treating code as plain text, Beep represents code elements using Abstract Syntax Tree (AST) paths. This captures the hierarchical relationship between a token (like a variable name) and the rest of the program structure (like an if statement or a loop).

The neural network architecture of Beep, featuring an LSTM-based encoder-decoder and a pointer network.

The core components include:

  • Encoder-Decoder with Pointer Network: The Encoder (using LSTMs) processes sub-tokens, AST paths, and potential change operators. The Pointer Network is the "secret sauce." Rather than trying to generate new code from scratch, it "points" to specific existing elements in the input code that are most likely to be buggy.
  • Joint Prediction: Beep doesn't just find the bug; it learns to predict the Operation Path simultaneously, providing a clear "recipe" for repair.
  • Repair Pipelines: The authors integrated Beep into two pipelines: one using a code completion engine (AnyCodeGen) to fill in "holes" created by Beep, and another using simple heuristics to swap tokens.

Evaluation and Key Results

The study leverages several well-known benchmarks: CoCoNut (for massive-scale training), ManySStuBs4J (simple bugs), and Defects4J (the gold standard for Java repair).

  • Localization Accuracy: When given a buggy method, Beep placed the correct buggy token at Top-1 for up to 46.9% of bugs in the CoCoNut dataset and 34.9% in Defects4J.
  • Efficiency: Beep filters out roughly 90% of non-buggy code tokens, drastically reducing the manual effort for developers or the computational effort for APR tools.
  • Repair Quality: In end-to-end testing, the Beep-driven pipelines achieved a 100% correctness ratio. Every single plausible patch generated was verified to be a semantically correct fix.
  • Speed: The median Number of Patch Candidates (NPC) needed to find a fix was only 2, significantly outperforming state-of-the-art tools like SimFix or TBar, which often try hundreds of candidates.

Discussion and Limitations

Beep builds on the theory that code is "natural" and repetitive. By narrowing the "mutation space" to a specific token, the risk of overfitting drops to near zero. However, some limitations persist:

  • Long-tail Bugs: Like most data-driven models, Beep struggles with unique or rare errors not well-represented in training data.
  • Method Declarations: The model currently finds it difficult to fix bugs in method signatures (e.g., changing a return type) because these have very short AST paths.
  • Multi-location Fixes: While Beep can handle some multi-location bugs, it is primarily optimized for fixes involving a single token or a small cluster of tokens.

Summary updated

BibTeX
@misc{wang2021beep,
  author = {Shangwen Wang and Kui Liu and Bo Lin and Li Li and Jacques Klein and Xiaoguang Mao and Tegawendé F. Bissyandé},
  title = {{Beep: Fine-grained Fix Localization by Learning to Predict Buggy Code Elements}},
  year = {2021},
  eprint = {2111.07739},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.07739},
}
Figure