logo

SCIENCE CHINA Information Sciences, Volume 61, Issue 1: 012107(2018) https://doi.org/10.1007/s11432-017-9153-3

A study on the changes of dynamic feature code when fixing bugs: towards the benefits and costs of Python dynamic features

More info
  • ReceivedFeb 18, 2017
  • AcceptedJun 19, 2017
  • PublishedDec 12, 2017

Abstract

Dynamic features in programming languages support the modification of the execution status at runtime, which is often considered helpful in rapid development and prototyping. However, it was also reported that some dynamic feature code tends to be change-prone or error-prone. We present the first study that analyzes the changes of dynamic feature code and the roles of dynamic features in bug-fix activities for the Python language. We used an AST-based differencing tool to capture fine-grained source code changes from 17926 bug-fix commits in 17 Python projects. Using this data, we conducted an empirical study on the changes of dynamic feature code when fixing bugs in Python. First, we investigated the characteristics of dynamic feature code changes, by comparing the changes between dynamic feature code and non-dynamic feature code when fixing bugs, and comparing dynamic feature changes between bug-fix and non-bugfix activities. Second, we explored 226 bug-fix commits to investigate the motivation and behaviors of dynamic feature changes when fixing bugs. The study results reveal that (1) the changes of dynamic feature code are significantly related to bug-fix activities rather than non-bugfix activities; (2) compared with non-dynamic feature code, dynamic feature code is inserted or updated more frequently when fixing bugs; (3) developers often insert dynamic feature code as type checks or attribute checks to fix type errors and attribute errors; (4) the misuse of dynamic features introduces bugs in dynamic feature code, and the bugs are often fixed by adding a check or adding an exception handling. As a benefit of this paper, we gain insights into the manner in which developers and researchers handle the changes of dynamic feature code when fixing bugs.


References

[1] Akerblom B, Stendahl J, Tumlin M, et al. Tracing dynamic features in Python programs. In: Proceedings of the 11th Working Conference on Mining Software Repositories, Hyderabad, 2014. 292--295. Google Scholar

[2] Holkner A, Harland J. Evaluating the dynamic behaviour of Python applications. In: Proceedings of the 32nd Australasian Conference on Computer Science, Wellington, 2009. 19--28. Google Scholar

[3] Bodden E, Sewe A, Sinschek J, et al. Taming reflection: aiding static analysis in the presence of reflection and custom class loaders categories and subject descriptors. In: Proceedings of the 33rd International Conference on Software Engineering, Waikiki, 2011. 241--250. Google Scholar

[4] Richards G, Hammer C, Burg B. The eval that men do: a large-scale study of the use of eval in JavaScript applications. In: Proceedings of the 25th European Conference on Object-oriented Programming, Lancaster, 2011. 52--78. Google Scholar

[5] Richards G, Lebresne S, Burg B, et al. An analysis of the dynamic behavior of JavaScript programs. ACM SIGPLAN Notices, 2010, 45: 1--12. Google Scholar

[6] Callau O, Robbes R, Tanter E, et al. How developers use the dynamic features of programming languages: the case of Smalltalk. In: Proceedings of the 8th Working Conference on Mining Software Repositories, Waikiki, 2011. 23--32. Google Scholar

[7] Dufour B, Goard C, Hendren L, et al. Measuring the dynamic behaviour of AspectJ programs. In: Proceedings of the 19th Annual ACM SIGPLAN Conference on Object-oriented Programming, Systems, Languages, and Applications, Vancouver, 2004. 150--169. Google Scholar

[8] Wang B B, Chen L, Ma W W Y, et al. An empirical study on the impact of Python dynamic features on change-proneness. In: Proceedings of the 27th International Conference on Software Engineering and Knowledge Engineering, Pittsburgh, 2015. 134--139. Google Scholar

[9] Park J, Lim I, Ryu S. Battles with false positives in static analysis of JavaScript web applications in the wild. In: Proceedings of the 38th International Conference on Software Engineering Companion, Austin, 2016. 61--70. Google Scholar

[10] Sanner M F. Python: a programming language for software integration and development. J Mol Graph Model, 1999, 17: 57--61. Google Scholar

[11] Chen Z F, Ma W W Y, Lin W, et al. Tracking down dynamic feature code changes against Python software evolution. In: Proceedings of the 3rd International Conference on Trustworthy Systems and Their Applications, Wuhan, 2016. 54--63. Google Scholar

[12] Qian J, Chen L, Xu B W. Finding shrink critical section refactoring opportunities for the evolution of concurrent code in trustworthy software. Sci China Inf Sci, 2013, 56: 012106. Google Scholar

[13] Chen L, Qian J, Zhou Y M, et al. Identifying extract class refactoring opportunities for internetware. Sci China Inf Sci, 2014, 57: 072103. Google Scholar

[14] Feng Y, Liu Q, Dou M Y, et al. Mubug: a mobile service for rapid bug tracking. Sci China Inf Sci, 2016, 59: 013101. Google Scholar

[15] Zhang J, Wang X, Hao D, et al. A survey on bug-report analysis. Sci China Inf Sci, 2015, 58: 021101. Google Scholar

[16] Chen L, Ma W W Y, Zhou Y M, et al. Empirical analysis of network measures for predicting high severity software faults. Sci China Inf Sci, 2016, 59: 122901. Google Scholar

[17] Kim S, Zimmermann T, Whitehead E J. Predicting faults from cached history. In: Proceedings of the 29th International Conference on Software Engineering, Minneapolis, 2007. 489--498. Google Scholar

[18] Fischer M, Pinzger M, Gall H. Populating a release history database from version control and bug tracking systems. In: Proceedings of the International Conference on Software Maintenance, Amsterdam, 2003. 23--32. Google Scholar

[19] Hall T. Some code smells have a significant but small effect on faults. ACM Trans Softw Eng Methodol, 2014, 23: 33. Google Scholar

[20] Khomh F, Penta M D, Gueheneuc Y G, et al. An exploratory study of the impact of antipatterns on class change- and fault-proneness. Empir Softw Eng, 2012, 17: 243--275. Google Scholar

[21] Zhong H, Su Z D. An empirical study on real bug fixes. In: Proceedings of the 37th International Conference on Software Engineering, Florence, 2015. 913--923. Google Scholar

[22] Monographs B. Statistical methods for research workers. In: Breakthroughs in Statistics. Berlin: Springer-Verlag, 1992. 66--70. Google Scholar

[23] Xu Z G, Liu P, Zhang X Y, et al. Python predictive analysis for bug detection. In: Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, Seattle, 2016. 121--132. Google Scholar

[24] Chen Z F, Chen L, Zhou Y M, et al. Dynamic slicing of Python programs. In: Proceedings of the 38th Computer Software and Applications Conference, Vasteras, 2014. 219--228. Google Scholar

[25] Xu Z G, Qian J, Chen L, et al. Static slicing for Python first-class objects. In: Proceedings of the 13th International Conference on Quality Software, Najing, 2013. 117--124. Google Scholar

[26] Chen Z F, Chen L, Xu B W. Hybrid information flow analysis for Python bytecode. In: Proceedings of the 11th Web Information System and Application Conference, Tianjin, 2014. 95--100. Google Scholar

[27] Chen L, Xu B W, Zhou T L, et al. A constraint based bug checking approach for Python. In: Proceedings of the 33rd Computer Software and Applications Conference, Seattle, 2009. 306--311. Google Scholar

[28] Vitousek M M, Kent A M, Siek J G, et al. Design and evaluation of gradual typing for Python. In: Proceedings of the 10th ACM Symposium on Dynamic Languages, Portland, 2014. 45--56. Google Scholar

[29] Xu Z G, Zhang X Y, Chen L, et al. Python probabilistic type inference with natural language support. In: Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, Seattle, 2016. 607--618. Google Scholar

[30] Akerblom B, Wrigstad T. Measuring polymorphism in Python programs. In: Proceedings of the 11th Symposium on Dynamic Languages, Pittsburgh, 2015. 114--128. Google Scholar

[31] Gorbovitski M, Stoller S D. Alias analysis for optimization of dynamic languages. In: Proceedings of the 6th Symposium on Dynamic Languages, Reno/Tahoe, 2010. 27--42. Google Scholar

[32] Lin W, Chen Z F, Ma W W Y, et al. An empirical study on the characteristics of Python fine-grained source code change types. In: Proceedings of the 32nd International Conference on Software Maintenance and Evolution, Raleigh, 2016. 188--199. Google Scholar

[33] Member S. Change distilling: tree differencing for fine-grained source code change extraction. IEEE Trans Softw Eng, 2007, 33: 725--743. Google Scholar

[34] Neamtiu I, Foster J S, Hicks M. Understanding source code evolution using abstract syntax tree matching. In: Proceedings of the 2005 International Workshop on Mining Software Repositories, St. Louis, 2005. 1--5. Google Scholar

[35] Sager T, Bernstein A, Pinzger M, et al. Detecting similar Java classes using tree algorithms. In: Proceedings of the 2006 International Workshop on Mining Software Repositories, Shanghai, 2006. 65--71. Google Scholar

[36] Apiwattanapong T, Orso A, Harrold M J. A differencing algorithm for object-oriented programs. In: Proceedings of the 19th IEEE International Conference on Automated Software Engineering, Linz, 2004. 2--13. Google Scholar

[37] Howitz S. Identifying the semantic and textual differences between two versions of a program. In: Proceedings of the ACM SIGPLAN 1990 Conference on Programming Language Design and Implementation, White Plains, 1990. 234--245. Google Scholar

[38] Raghavan S, Rohana R, Leon D, et al. Dex: a semantic-graph differencing tool for studying changes in large code bases. In: Proceedings of the 20th IEEE International Conference on Software Maintenance, Chicago, 2004. 188--197. Google Scholar

[39] Kim M, Notkin D. Program element matching for multi-version program analyses. In: Proceedings of the 2006 International Workshop on Mining Software Repositories, Shanghai, 2006. 58--64. Google Scholar

[40] Purushothaman R, Perry D E. Toward understanding the rhetoric of small source code changes. IEEE Trans Softw Eng, 2005, 31: 511--526. Google Scholar

[41] Voinea L, Telea A. CVSscan: visualization of code evolution. In: Proceedings of the 2005 ACM Symposium on Software Visualization, St. Louis, 2005. 47--56. Google Scholar

[42] Omori T, Maruyama K. A change-aware development environment by recording editing operations of source code. In: Proceedings of the 2008 International Working Conference on Mining Software Repositories, Leipzig, 2008. 31--34. Google Scholar

[43] Rastkar S, Murphy G C. Why did this code change? In: Proceedings of the 2013 International Conference on Software Engineering, San Francisco, 2013. 1193--1196. Google Scholar

[44] Canfora G, Cerulo L, Cimitile M, et al. How changes affect software entropy: an empirical study. Empir Softw Eng, 2014, 19: 1--38. Google Scholar

[45] Kamei Y, Shihab E, Adams B, et al. A large-scale empirical study of just-in-time quality assurance. IEEE Trans Softw Eng, 2013, 39: 757--773. Google Scholar

[46] Wen M, Wu R X, Cheung S C. Locus: locating bugs from software changes. In: Proceedings of the 31st IEEE/ACM International Conference on Automated Software Engineering, Singapore, 2016. 262--273. Google Scholar

[47] Zhao Y Y, Leung H, Yang Y B, et al. Towards an understanding of change types in bug fixing code. Inform Softw Tech, 2017, 86: 37--53. Google Scholar

[48] Pan K, Kim S, Whitehead E J Jr. Toward an understanding of bug fix patterns. Empir Softw Eng, 2009, 14: 286--315. Google Scholar

  • Figure 1

    Motivating example.

  • Figure 2

    Infrastructure of analyzing feature changes at bug-fix commits.

  • Figure 3

    Distribution of three change types of dynamic features and non-dynamic features in fixing bugs.

  • Table 1   The categories of Python dynamic features
    Introspection Object changes Code generation Library loading
    type vars setattr compile __import__
    getattr callable delattr eval reload
    hasattr locals del exec
    isinstance globals execfile
    issubclass super
  • Table 2   Descriptive information of analyzed subject projects
    Domain Projects Avg. of #files Avg. of #commits Avg. of #bugs
    Data processing Scipy, Numpy, Matplotlib, Scikit-learn 607 16727 1363
    Web Django, Django-rest-framework, Boto 1014 11630 8849
    Media Beets, Youtube-dl 372 7749 205
    Deployment Ansible, Deis, Fabric 188 9019 1415
    Development Ipython, Sqlmap 359 14109 735
    Visualization Glances, Powerline, Wagtail 220 3209 418
  • Table 3   Number of bug-fix commits that experienced dynamic feature changes in 17 subject projects
    Dynamic features Insert Delete Update Change
    hasattr 370 149 261 552
    getattr 345 133 420 671
    type 65 38 72 151
    issubclass 24 10 32 54
    isinstance 729 249 499 1014
    vars 2 2 1 5
    callable 64 25 26 88
    globals 2 2 2 5
    locals 5 4 2 8
    super 484 156 201 536
    setattr 100 45 100 180
    delattr 9 2 8 18
    del 103 68 66 183
    compile 3 0 3 6
    eval 3 1 2 5
    exec 3 0 7 10
    execfile 1 0 0 1
    __import__ 50 32 126 167
    reload 3 3 0 5
    Total 1994 719 2234 3334
  • Table 4   Result of Fishers exact test which examines the association between feature changes and bug-fix activities
    Dynamic features Insert Delete Update Change
    $p$-value OR $p$-value OR $p$-value OR $p$-value OR
    hasattr 1.28E$-$24 2.079794 1.54E$-$08 1.873966 2.68E$-$13 1.925916 6.58E$-$26 1.958367
    getattr 7.64E$-$27 2.177587 0.000182 1.542809 1.53E$-$26 2.417415 1.34E$-$28 2.059578
    type 0.014909 0.724520 0.605477 0.900660 0.380095 0.870287 0.099100 0.832316
    issubclass 0.194856 1.365870 0.416609 1.359397 0.015452 1.782317 0.110369 1.398416
    isinstance 3.07E$-$38 1.924559 6.78E$-$07 1.534279 3.79E$-$16 1.712424 1.43E$-$37 1.814357
    callable 7.03E$-$07 2.301692 0.000777 2.31738 0.166888 1.416322 2.13E$-$08 2.270205
    super 3.97E$-$45 2.72281 1.56E$-$09 2.028205 1.03E$-$18 2.653804 4.97E$-$47 2.504783
    setattr 8.76E$-$15 2.865361 5.57E$-$05 2.300739 5.11E$-$22 5.308334 3.92E$-$14 2.517646
    delattr 5.69E$-$05 7.417112 0.185077 3.02071 0.000286 10.87703 2.66E$-$05 6.232933
    del 0.019203 1.304067 0.004101 1.516179 0.004678 1.555887 0.001716 1.347267
    __import__ 2.45E$-$14 4.588762 2.52E$-$05 3.358702 3.35E$-$14 4.64069 2.15E$-$14 3.834873
  • Table 5   Description of the bugs and feature inserts for fixing bugs
    Bug Bug causes Introduced dynamic features Change behaviors #Occurrences
    Wrong type Wrong execution result, invalid input, incompatible execution environment, incompatible library version isinstance, issubclass, type Add type check 17
    Invalid access of attribute Never created attribute, deleted attribute, buggy attribute name, or null class/instance object hasattr, getattr Add attribute check 8
    MRO confliction Deriving new class wrongly in multiple inheritance super Support MRO 2
  • Table 6   Description of bugs and feature updates or deletes for fixing bugs
    Bug Bug cause Updated/Deleted dynamic features Change behaviors #occurrences
    Wrong type check Supporting too specific types, too generic types, or neighboring types isinstance, issubclass, type Change type parameter 20
    Dynamic import error Non-existing module (incompatible library version, wrong module name, absent module), wrong configuration parameter __import__ Add exception handling, add check before dynamic code, add check after dynamic code, change configuration parameter 14
    Invalid dynamic łinebreak access of attribute Non-existing attribute (already deleted attribute, non-existing class/instance, wrong attribute name, wrong class/instance name) getattr Add exception handling, return default value 10
    Invalid dynamic updating of attribute value Updating the attribute that cannot be overwritten setattr Add check before dynamic code 6
    Dynamic compile łinebreak error Invalid access of code to be compiled, wrong configuration parameter compile Add exception handling, add check before dynamic code, change configuration parameter 4
    Invalid dynamic deletion of attribute Non-existing attribute (already deleted attribute, non-existing class/instance, wrong attribute name, wrong class/instance name) delattr Add exception handling 4
    Invalid dynamic deletion of variable Non-existing variable (already deleted variable, wrong variable name) del Add exception handling 3
    Undefined variable error Typo instance, super Change variable name 3
    Dynamic code łinebreak execution error Invalid expression or statement to be evaluated eval, exec Add exception handling, add check before dynamic code, add check after dynamic code 3
  • Table 7   Change patterns in fixing erroneous dynamic feature code
    Bug pattern Precondition Change type
    isinstance(object, typeinfo) Wrong type check of object Parameter update: typeinfo
    issubclass(object, typeinfo) Wrong type check of object Parameter update: typeinfo
    type(object) = typeinfo Wrong type check of object Parameter update: typeinfo
    __import__(name[,~globals[,~locals[,~fromlist[,~level]) Non-existing module: name Statement insert: try-except statement insert: if
    __import__(name[,~globals[,~locals[,~fromlist[,~level]) Wrong configuration Parameter update: globals, locals, fromlist, level
    getattr(object, name) Non-existing attribute: name Statement insert: try-except parameter insert: DefaultValue
    setattr(object, name, value) Unallowed to overwrite: name Statement insert: if
    compile(source, filename, mode[,~flags[,~dont\_inherit[,~optimize]) Invalid access of source Statement insert: try-except
    compile(source, filename, mode[,~flags[,~dont\_inherit[,~optimize]) Wrong type of source Statement insert: if
    compile(source, filename, mode[,~flags[,~dont\_inherit[,~optimize]) Wrong configuration Parameter update: mode, flags, dont_inherit, optimize
    eval(expression) Invalid expression: expression Statement insert: try-except statement insert: if
    exec(object) Invalid statement: object Statement insert: try-except statement insert: if
    del name Non-existing variable: name Statement insert: try-except
    delattr(object, name) Non-existing attribute: name Statement insert: try-except

Copyright 2020 Science China Press Co., Ltd. 《中国科学》杂志社有限责任公司 版权所有

京ICP备18024590号-1