Modern Java projects increasingly adopt static analysis tools that prevent null-pointer exceptions by treating nullness as a type property. However, integrating such tools into large, existing codebases remains a significant challenge. While annotation inference can eliminate many errors automatically, a subset of residual errors -- typically a mix of real bugs and false positives -- often persist and can only be resolved via code changes. Manually addressing these errors is tedious and error-prone. Large language models (LLMs) offer a promising path toward automating these repairs, but naively-prompted LLMs often generate incorrect, contextually-inappropriate edits. We present NullRepair, a system that integrates LLMs into a structured workflow for resolving the errors from a nullability checker. NullRepair's decision process follows a flowchart derived from manual analysis of 200 real-world errors. It leverages static analysis to identify safe and unsafe usage regions of symbols, using error-free usage examples to contextualize model prompts. Patches are generated through an iterative interaction with the LLM that incorporates project-wide context and decision logic. Our evaluation on 12 real-world Java projects shows that NullRepair resolves 63% of the 1,119 nullability errors that remain after applying a state-of-the-art annotation inference technique. Unlike two baselines (single-shot prompt and mini-SWE-agent), NullRepair also largely preserves program semantics, with all unit tests passing in 10/12 projects after applying every edit proposed by NullRepair, and 98% or more tests passing in the remaining two projects.


翻译:现代Java项目日益采用静态分析工具,通过将可空性视为类型属性来防止空指针异常。然而,将此类工具集成到大型现有代码库中仍然是一项重大挑战。虽然注解推断可以自动消除许多错误,但残留错误的一个子集——通常是实际缺陷和误报的混合——往往持续存在,只能通过代码更改来解决。手动处理这些错误既繁琐又容易出错。大型语言模型为实现这些修复的自动化提供了一条有前景的路径,但简单提示的LLM经常生成不正确、上下文不恰当的编辑。我们提出了NullRepair系统,该系统将LLM集成到结构化工作流中,用于解决可空性检查器产生的错误。NullRepair的决策流程遵循通过手动分析200个实际错误得出的流程图。它利用静态分析来识别符号的安全和不安全使用区域,并使用无错误的使用示例来为模型提示提供上下文。补丁通过与LLM的迭代交互生成,该交互结合了项目范围的上下文和决策逻辑。我们在12个实际Java项目上的评估表明,在应用最先进的注解推断技术后,NullRepair解决了1,119个可空性错误中的63%。与两个基线方法(单次提示和mini-SWE-agent)不同,NullRepair还在很大程度上保留了程序语义:在应用NullRepair提出的所有编辑后,10/12项目的所有单元测试均通过,其余两个项目中98%或更多的测试通过。

0
下载
关闭预览

相关内容

大型语言模型系统中提示缺陷的分类学
专知会员服务
8+阅读 · 2025年9月19日
利用多个大型语言模型:关于LLM集成的调研
专知会员服务
35+阅读 · 2025年2月27日
【NeurIPS2024】用于缺失值数据集的可解释广义加性模型
专知会员服务
18+阅读 · 2024年12月7日
大型语言模型自动程序修复的系统文献综述
专知会员服务
42+阅读 · 2024年5月5日
【ICLR2024】能检测到LLM产生的错误信息吗?
专知会员服务
25+阅读 · 2024年1月23日
LLMCad:快速可扩展的设备上大型语言模型推理
专知会员服务
35+阅读 · 2023年9月11日
使用 Canal 实现数据异构
性能与架构
20+阅读 · 2019年3月4日
用模型不确定性理解模型
论智
11+阅读 · 2018年9月5日
NLP通用模型诞生?一个模型搞定十大自然语言常见任务
人工智能头条
10+阅读 · 2018年6月29日
【学界】机器学习模型的“可解释性”到底有多重要?
GAN生成式对抗网络
12+阅读 · 2018年3月3日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员