On the "Naturalness" of Buggy Code

被引:163
作者
Ray, Baishakhi [1 ]
Hellendoorn, Vincent [2 ]
Godhane, Saheel [2 ]
Tu, Zhaopeng [3 ]
Bacchelli, Alberto [4 ]
Devanbu, Premkumar [2 ]
机构
[1] Univ Virginia, Charlottesville, VA 22903 USA
[2] Univ Calif Davis, Davis, CA 95616 USA
[3] Huawei Technol Co Ltd, Shenzhen, Guangdong, Peoples R China
[4] Delft Univ Technol, Delft, Netherlands
来源
2016 IEEE/ACM 38TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE) | 2016年
基金
美国国家科学基金会;
关键词
PREDICTING FAULTS;
D O I
10.1145/2884781.2884848
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Real software, the kind working programmers produce by the kLOC to solve real-world problems, tends to be "natural", like speech or natural language; it tends to be highly repetitive and predictable. Researchers have captured this naturalness of software through statistical models and used them to good effect in suggestion engines, porting tools, coding standards checkers, and idiom miners. This suggests that code that appears improbable, or surprising, to a good statistical language model is "unnatural" in some sense, and thus possibly suspicious. In this paper, we investigate this hypothesis. We consider a large corpus of bug fix commits (ca.7,139), from 10 different Java projects, and focus on its language statistics, evaluating the naturalness of buggy code and the corresponding fixes. We find that code with bugs tends to be more entropic (i.e. unnatural), becoming less so as bugs are fixed. Ordering files for inspection by their average entropy yields cost-effectiveness scores comparable to popular defect prediction methods. At a finer granularity, focusing on highly entropic lines is similar in cost-effectiveness to some well-known static bug finders (PMD, FindBugs) and ordering warnings from these bug finders using an entropy measure improves the cost-effectiveness of inspecting code implicated in warnings. This suggests that entropy may be a valid, simple way to complement the effectiveness of PMD or FindBugs, and that search-based bug-fixing methods may benefit from using entropy both for fault-localization and searching for fixes.
引用
收藏
页码:428 / 439
页数:12
相关论文
共 56 条
[1]   Mining Idioms from Source Code [J].
Allamanis, Miltiadis ;
Sutton, Charles .
22ND ACM SIGSOFT INTERNATIONAL SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING (FSE 2014), 2014, :472-483
[2]  
Allamanis Miltos, 2014, P 22 INT S FDN SOFTW
[3]   Statistical Learning of API Mappings for Language Migration [J].
Anh Tuan Nguyen ;
Hoan Anh Nguyen ;
Tung Thanh Nguyen ;
Nguyen, Tien N. .
36TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE COMPANION 2014), 2014, :618-619
[4]   Migrating Code with Statistical Machine Translation [J].
Anh Tuan Nguyen ;
Tung Thanh Nguyen ;
Nguyen, Tien N. .
36TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE COMPANION 2014), 2014, :544-547
[5]  
[Anonymous], 2005, PMD applied
[6]  
[Anonymous], 2005, DATA MINING
[7]  
[Anonymous], 2007, 6th joint meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on the Foundations of Software Engineering (ESEC/FSE), DOI DOI 10.1145/1287624.1287632
[8]  
[Anonymous], 2007, 3 INT WORKSH PRED MO
[9]  
[Anonymous], 2014, PROMISE 14 P 10 INT
[10]   A systematic and comprehensive investigation of methods to build and evaluate fault prediction models [J].
Arisholm, Erik ;
Briand, Lionel C. ;
Johannessen, Eivind B. .
JOURNAL OF SYSTEMS AND SOFTWARE, 2010, 83 (01) :2-17