arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2512.20334cs.SE
收藏

评论陷阱:缺陷评论代码如何增强AI辅助代码生成中的缺陷

Comment Traps: How Defective Commented-out Code Augment Defects in AI-Assisted Code Generation

Sun Yat-sen University(中山大学)

Yuan Huang, Yukang Zhou, Xiangping Chen, Zibin Zheng

AI总结:

本研究探讨了缺陷注释代码如何影响AI编码助手生成缺陷代码,发现其生成缺陷率高达58.17%,并指出需提升AI编码助手的鲁棒性与安全性。

摘要:

随着大型语言模型在代码生成中的快速发展,像GitHub Copilot和Cursor这样的AI驱动编辑器正在革新软件开发实践。同时,研究已识别出生成代码中潜在的缺陷。以往的研究主要探讨了代码上下文如何影响缺陷代码的生成,往往忽略了注释出的代码(CO代码)中的缺陷影响。AI编码助手在提示中对CO代码的解读会影响其生成的代码。 本研究评估了AI编码助手,GitHub Copilot和Cursor,如何受到缺陷CO代码的影响。实验结果表明,上下文中的缺陷CO代码导致AI编码助手生成更多缺陷代码,达到最高58.17%。我们的发现进一步表明,工具并不简单地复制上下文中的缺陷代码。相反,它们会主动推理以完成不完整的缺陷模式,并在干扰因素如错误缩进或标签的情况下继续生成缺陷代码。即使有明确指示忽略缺陷CO代码,缺陷减少的幅度也不超过21.84%。这些发现强调了在AI编码助手中改进鲁棒性和安全措施的必要性。

英文摘要:

With the rapid development of large language models in code generation, AI-powered editors such as GitHub Copilot and Cursor are revolutionizing software development practices. At the same time, studies have identified potential defects in the generated code. Previous research has predominantly examined how code context influences the generation of defective code, often overlooking the impact of defects within commented-out code (CO code). AI coding assistants' interpretation of CO code in prompts affects the code they generate. This study evaluates how AI coding assistants, GitHub Copilot and Cursor, are influenced by defective CO code. The experimental results show that defective CO code in the context causes AI coding assistants to generate more defective code, reaching up to 58.17 percent. Our findings further demonstrate that the tools do not simply copy the defective code from the context. Instead, they actively reason to complete incomplete defect patterns and continue to produce defective code despite distractions such as incorrect indentation or tags. Even with explicit instructions to ignore the defective CO code, the reduction in defects does not exceed 21.84 percent. These findings underscore the need for improved robustness and security measures in AI coding assistants.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑