Introduction
Fault localisation (FL)—the process of identifying the exact location of a bug within source code—remains one of the most resource-intensive phases of the software development lifecycle. Traditional automated techniques have historically relied on two primary paradigms: Spectrum-Based Fault Localisation (SBFL), which utilizes test coverage statistics, and Mutation-Based Fault Localisation (MBFL), which analyzes the impact of code mutations on test outcomes. While these methods provide statistical indicators of buggy code, they often lack the "semantic depth" required to understand complex logical errors.
This paper presents a rigorous evaluation of Large Language Models (LLMs), specifically ChatGPT-3.5 and ChatGPT-4, in the realm of FL. The study investigates whether these models can transcend statistical formulas to reason through bugs, and how factors such as prompt design and code context influence their diagnostic accuracy.
Methodology
The researchers conducted a comprehensive empirical study comparing LLMs against established baselines, including SBFL (Ochiai and Dstar formulas), MBFL (Metallaxis), and SmartFL, a state-of-the-art probabilistic approach. The experimental design focused on several key variables:
- Prompt Engineering Strategies: Two primary strategies were evaluated: Origin (providing only the target function) and Log (providing the function alongside the failed test case and its associated error log).
- Context Levels: To determine the impact of code volume, models were tested at the statement, function, and class levels.
- Ablation Studies: Components such as reasoning explanations and error logs were systematically removed to isolate the drivers of performance.
- Stochasticity Management: To account for the non-deterministic nature of LLMs, each experiment was repeated five times, with results averaged to ensure reliability.
Dataset Analysis
The study utilized two distinct datasets to ensure a robust evaluation. The primary benchmark was Defects4J, an industry-standard collection of real-world Java vulnerabilities. As shown in Table 1, the benchmark encompasses a diverse range of projects with varying code lengths and fault densities.
To address potential "data leakage"—the risk that the models were trained on the Defects4J repository—the authors introduced StuDefects. This new dataset consists of 77 unique programs from student submissions written in 2022 and later, ensuring that ChatGPT-4 (with a late-2021 training cutoff) encountered the bugs for the first time.
Key Insights and Results
The "Log" is King
The single most significant factor in boosting LLM performance was the inclusion of the error log. By providing dynamic execution information, such as stack traces and failure messages, ChatGPT-4 was able to "triangulate" errors more effectively, resulting in a 25.6% increase in accuracy over code-only prompts.
The Context Paradox and Performance Cliff
A critical finding of the study is the "performance cliff" associated with context size. While one might expect more code to provide better context, the opposite occurred. At the function level, ChatGPT-4 (Log) achieved a TOP-1 accuracy of 23.13, outperforming the state-of-the-art SmartFL by 46.9%. However, when the context was expanded to the class level, ChatGPT-4’s performance plummeted by nearly 50%, falling below the accuracy of traditional statistical methods. This suggests that LLMs currently struggle with "noise" or become "lost in the middle" when faced with large, irrelevant code blocks.
Reasoning and Consistency
Forcing the model to provide a "reason" for its suspicion (Chain of Thought prompting) significantly improved results. Furthermore, ChatGPT-4 demonstrated much higher consistency than its predecessor, with a variance range of only 0.07–0.12 across repeated trials, marking it as a more reliable tool for practical deployment.
Conclusion and Future Work
While ChatGPT-4 represents a significant leap forward in function-level fault localisation, the context window bottleneck remains a major hurdle for large-scale software engineering. Future research must address this by developing intelligent context filtering techniques, fine-tuning models specifically for debugging tasks, or creating hybrid systems that combine the statistical robustness of SBFL with the semantic reasoning capabilities of LLMs.
Summary updated