arXiv:2503.06510cs.SEcs.CL2025-03中稿 · AAAI

让修复代码更贴近原代码,减少无谓改动。

Less is More: Adaptive Program Repair with Bug Localization and Preference Learning

  • 分两阶段修复:先定位错误,再生成最小化修改的补丁。
  • 在Defects4J数据集上修复成功率提升至68.3%,优于基线。
  • 适合关注代码一致性与简洁性的开发人员和工具研究者。

自动化程序修复(APR)旨在自动为有缺陷的代码生成补丁。然而,多数研究聚焦于生成正确补丁,忽略了修复后代码与原始错误代码的一致性。如何实现自适应修复并生成最小修改的补丁尚未被充分探索。为此,我们首次提出新任务AdaPR(自适应程序修复),并设计两阶段方法AdaPatcher(自适应补丁生成器)以增强修复效果并保持一致性。第一阶段采用具有自调试学习能力的漏洞定位器精准定位错误位置;第二阶段训练程序修改器,确保修复前后代码的一致性。该修改器引入位置感知修复学习策略,基于定位结果生成补丁,结合选择性参考的混合训练策略与自适应偏好学习,优先生成修改量更少的补丁。实验表明,本方法在多个基准测试中显著优于现有基线,验证了所提两阶段框架在新任务中的有效性。

原文摘要 · Abstract (English)

Automated Program Repair (APR) is a task to automatically generate patches for the buggy code. However, most research focuses on generating correct patches while ignoring the consistency between the fixed code and the original buggy code. How to conduct adaptive bug fixing and generate patches with minimal modifications have seldom been investigated. To bridge this gap, we first introduce a novel task, namely AdaPR (Adaptive Program Repair). We then propose a two-stage approach AdaPatcher (Adaptive Patch Generator) to enhance program repair while maintaining the consistency. In the first stage, we utilize a Bug Locator with self-debug learning to accurately pinpoint bug locations. In the second stage, we train a Program Modifier to ensure consistency between the post-modified fixed code and the pre-modified buggy code. The Program Modifier is enhanced with a location-aware repair learning strategy to generate patches based on identified buggy lines, a hybrid training strategy for selective reference and an adaptive preference learning to prioritize fewer changes. The experimental results show that our approach outperforms a set of baselines by a large margin, validating the effectiveness of our two-stage framework for the newly proposed AdaPR task.

程序修复自适应修复偏好学习

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。