Retrofitting Code Using LLMs to Support Exceptional Behavior
作者: Linghan Zhong, Jiyang Zhang, Jayanth Srinivasa, Junyi Jessy Li, Milos Gligoric
分类: cs.SE, cs.CL
发布日期: 2026-09-09
备注: ISSRE 2026
💡 一句话要点
提出EXCODER以自动生成异常处理代码
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
📋 核心要点
- 现有方法在大型代码库中手动编写异常相关代码(ERC)效率低下,且容易出错。
- 本文提出EXCODER,通过上下文工程和LLMs结合,自动生成缺失的ERC以满足异常行为测试。
- 实验结果表明,EXCODER在开发者编写的测试套件上实现了显著的性能提升,尤其在通过率上超过基线。
- method_zh
📝 摘要(中文)
异常相关代码(ERC)是软件系统中至关重要的组成部分,允许开发者检测和处理偏离预期程序行为的异常状态。然而,在大型代码库中手动编写ERC非常繁琐。本文提出了一项新任务:为现有代码自动添加ERC。我们设计并实现了EXCODER,通过上下文工程帮助大型语言模型(LLMs)完成这一任务。EXCODER结合静态和动态程序分析,向LLMs提供提取的上下文信息。通过在GitHub Java代码库中构建基准,我们验证了EXCODER的有效性,结果显示其在自动代码生成方面提供了有效的解决方案,尤其是在测试驱动开发中实现ERC的首个方法。
🖼️ 关键图片
📄 摘要(原文)
Exception Related Code (ERC), which includes throw statements, conditions (if statements) that guard those throw statements, and try/catch blocks, is an essential component of software systems, allowing developers to detect and handle exceptional states that deviate from the expected program behavior. However, manually writing ERC across large codebases is tedious. We propose a novel task: retrofitting existing code with ERC. Namely, given code (without ERC) and Exceptional Behavior Tests (EBTs) (e.g., check if method throws InvalidArgumentException if null is given as the value to the argument) we aim to automatically generate missing ERC, such that the given tests pass. We design and implement Exception Coder (EXCODER) that performs context engineering to help Large Language Models (LLMs) tackle this task. EXCODER integrates static and dynamic program analysis with LLMs by providing the extracted contextual information to the LLMs. To evaluate EXCODER, we build a benchmark constructed from GitHub Java repositories, where we systematically remove ERC in 304 methods from 75 projects. Our results demonstrate that EXCODER provides an effective, though imperfect, solution to this problem in automated code generation, offering developers the first way to implement ERC following test-driven development. When combined with Qwen 2.5 Coder 32b, EXCODER achieves pass@1, 5, and 10 rates of 85.92% (12.56 percentage points over baseline), 86.18% (12.82 p.p. over baseline), and 86.51% (13.15 p.p. over baseline), respectively, on developer-written test suites. Our manual inspection of the generated code further reveals limitations of EXCODER, pointing to directions for future work.