评估重构代码的缺陷倾向:一项纵向多项目研究
Assessing the Bug-Proneness of Refactored Code: A Longitudinal Multi-Project Study
AI总结:
本文对12个开源项目开展纵向研究,分析不同重构特征与缺陷的长期关系,发现单一重构和顺手式重构反而可能增加缺陷风险,且相关缺陷难以被现有检测技术发现。
摘要:
重构是软件开发中的常见实践,旨在改善代码的内部结构,使其更易于理解和修改。因此,人们通常认为重构会降低代码出现缺陷的可能性。然而在实践中,重构是一项复杂任务,会以不同方式应用(例如不同的重构类型、单一重构与复合重构),并具有多种目的(例如根管式重构与顺手式重构)。因此,某些重构可能在无意中使代码更容易出现缺陷。遗憾的是,现有文献对重构的不同特征与缺陷之间的长期关系研究有限。本文呈现了一项针对12个开源软件项目的纵向研究,分析了27,450次重构、6,051个已报告缺陷,以及49,250个由静态分析工具检测到的缺陷。尽管我们的研究证实了“重构代码比未重构代码更不易出现缺陷”这一直觉,但我们也在其他方面扩展或反驳了已有知识体系。第一,经历多次重构的代码元素并不比经历单次重构的元素更不易出现缺陷;单次重构指在同一提交中未与其他重构共同执行的重构。第二,在所有分析项目中,单一重构经常引发缺陷。第三,受到在同一提交中与其他非重构更改共同进行的重构(即顺手式重构)影响的代码元素通常容易出现缺陷。最后,许多此类由重构引发的缺陷无法通过用于检测保持行为重构的最先进技术揭示。
英文摘要:
Refactoring is a common practice in software development, aimed at improving the internal code structure in order to make it easier to understand and modify. Consequently, it is often assumed that refactoring makes the code less prone to bugs. However, in practice, refactoring is a complex task and applied in different ways (e.g., various refactoring types, single vs. composite refactorings) and with a variety of purposes (e.g., root-canal vs. floss refactoring). Therefore, certain refactorings can inadvertently make the code more prone to bugs. Unfortunately, there is limited research in the literature on the long-term relationship between the different characteristics of refactorings and bugs. This paper presents a longitudinal study of 12 open source software projects, where 27,450 refactorings, 6,051 reported bugs, and 49,250 bugs detected with static analysis tools were analyzed. While our study confirms the common intuition that refactored code is less bug-prone than non-refactored code, we also extend or contradict existing body of knowledge in other ways. First, a code element that undergoes multiple refactorings is not less bug-prone than an element that undergoes a single refactoring. A single refactoring is the one not performed in conjunction with other refactorings in the same commit. Second, single refactorings often induce the occurrence of bugs across all analyzed projects. Third, code elements affected by refactorings made in conjunction with other non-refactoring changes in the same commit (i.e., floss refactorings) are often bug-prone. Finally, many of such bugs induced by refactoring cannot be revealed with state-of-the-art techniques for detecting behavior-preserving refactorings.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。