Content deleted Content added
→Data-driven: syntax fix |
cleaning up extensive COI / selfcite |
||
Line 1:
{{short description|Automatic repair of software bugs}}
'''Automatic bug-fixing''' is the automatic [[Patch (computing)|repair]] of [[software bug]]s without the intervention of a human programmer.<ref>{{Cite journal |last=Rinard |first=Martin C. |year=2008 |title=Technical perspective ''Patching'' program errors |journal=Communications of the ACM |volume=51 |issue=12 |pages=86 |doi=10.1145/1409360.1409381 |s2cid=28629846}}</ref><ref>{{Cite journal |last=Harman |first=Mark |year=2010 |title=Automated patching techniques |journal=Communications of the ACM |volume=53 |issue=5 |pages=108 |doi=10.1145/1735223.1735248 |s2cid=9729944}}</ref> It is also commonly referred to as ''automatic patch generation'', ''automatic bug repair'', or ''automatic program repair''.
== Specification ==
Line 14:
=== Generate-and-validate ===
Generate-and-validate approaches compile and test each candidate patch to collect all validated patches that produce expected outputs for all inputs in the test suite.<ref name="genprog2009" /><ref name="kali" /> Such a technique typically starts with a test suite of the program, i.e., a set of [[test cases]], at least one of which exposes the bug.<ref name="genprog2009" /><ref name="prophet" /><ref name="rsrepair">{{Cite book |last1=Qi |first1=Yuhua |title=Proceedings of the 36th International Conference on Software Engineering |last2=Mao |first2=Xiaoguang |last3=Lei |first3=Yan |last4=Dai |first4=Ziying |last5=Wang |first5=Chengsong |date=2014 |publisher=ACM |isbn=978-1-4503-2756-5 |series=ICSE 2014 |___location=Austin, Texas |pages=254–265 |chapter=The Strength of Random Search on Automated Program Repair |doi=10.1145/2568225.2568254 |s2cid=14976851}}</ref><ref name="spr">{{Cite book |last1=Long |first1=Fan |title=Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering |last2=Rinard |first2=Martin |date=2015 |publisher=ACM |isbn=978-1-4503-3675-8 |series=ESEC/FSE 2015 |___location=Bergamo, Italy |pages=166–178 |chapter=Staged Program Repair with Condition Synthesis |citeseerx=10.1.1.696.9059 |doi=10.1145/2786805.2786811 |s2cid=5987616}}</ref> An early generate-and-validate bug-fixing systems is GenProg.<ref name="genprog2009" /> The effectiveness of generate-and-validate techniques remains controversial, because they typically do not provide [[#Limitations of automatic bug-fixing|patch correctness guarantees]].<ref name="kali" /
<!-- mutation based repair -->
One way to generate candidate patches is to apply [[program mutation|mutation operators]] on the original program. Mutation operators manipulate the original program, potentially via its [[abstract syntax tree]] representation, or a more coarse-grained representation such as operating at the [[Statement (programming)|statement]]-level or [[Block (programming)|block]]-level. Earlier [[Genetic improvement (computer science)|genetic improvement]] approaches operate at the statement level and carry out simple delete/replace operations such as deleting an existing statement or replacing an existing statement with another statement in the same source file.<ref name=genprog2009 /><ref name="genprog2012">{{Cite book |last1=Le Goues |first1=Claire |title=2012 34th International Conference on Software Engineering (ICSE) |last2=Dewey-Vogt |first2=Michael |last3=Forrest |first3=Stephanie |last4=Weimer |first4=Westley |date=2012 |publisher=IEEE |isbn=978-1-4673-1067-3 |pages=3–13 |chapter=A Systematic Study of Automated Program Repair: Fixing 55 out of 105 Bugs for $8 Each |citeseerx=10.1.1.661.9690 |doi=10.1109/ICSE.2012.6227211 |s2cid=10987936}}</ref> Recent approaches use more fine-grained operators at the [[abstract syntax tree]] level to generate more diverse set of candidate patches.<ref name=spr /> Notably, the statement deletion mutation operator, and more generally removing code, is a reasonable repair strategy, or at least a good fault localization strategy.<ref>{{Cite journal |last1=Qi |first1=Zichao |last2=Long |first2=Fan |last3=Achour |first3=Sara |last4=Rinard |first4=Martin |date=2015-07-13 |title=An analysis of patch plausibility and correctness for generate-and-validate patch generation systems |url=http://dx.doi.org/10.1145/2771783.2771791 |journal=Proceedings of the 2015 International Symposium on Software Testing and Analysis |pages=24–36 |___location=New York, NY, USA |publisher=ACM |doi=10.1145/2771783.2771791|hdl=1721.1/101586 |isbn=9781450336208 |s2cid=6845282 }}</ref>
<!-- fix templates -->
Another way to generate candidate patches consists of using fix templates. Fix templates are typically predefined changes for fixing specific classes of bugs.<ref name=par /> Examples of fix templates include inserting a [[Conditional (computer programming)|conditional statement]] to check whether the value of a variable is null to fix null pointer exception, or changing an integer constant by one to fix off-by-one errors.<ref name="par" />
=== Synthesis-based ===
Line 32 ⟶ 29:
Under certain assumptions, it is possible to state the repair problem as a synthesis problem.
SemFix<ref name="semfix" /> and Nopol<ref name="nopol" /> uses component-based synthesis.<ref>{{Cite book |last1=Jha |first1=Susmit |url=http://techreports.lib.berkeley.edu/accessPages/EECS-2010-15.html |title=Oracle-guided component-based program synthesis |last2=Gulwani |first2=Sumit |last3=Seshia |first3=Sanjit A. |last4=Tiwari |first4=Ashish |date=2010-05-01 |publisher=ACM |isbn=9781605587196 |pages=215–224 |doi=10.1145/1806799.1806833 |s2cid=6344783}}</ref>
Dynamoth
S3<ref>{{Cite book |last1=Le |first1=Xuan-Bach D. |url=https://ink.library.smu.edu.sg/sis_research/3917 |title=Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering - ESEC/FSE 2017 |last2=Chu |first2=Duc-Hiep |last3=Lo |first3=David |last4=Le Goues |first4=Claire |last5=Visser |first5=Willem |date=2017-08-21 |publisher=ACM |isbn=9781450351058 |pages=593–604 |doi=10.1145/3106237.3106309 |s2cid=1503790}}</ref> is based on syntax-guided synthesis.<ref>{{Cite book |last1=Alur |first1=Rajeev |title=2013 Formal Methods in Computer-Aided Design |last2=Bodik |first2=Rastislav |last3=Juniwal |first3=Garvit |last4=Martin |first4=Milo M. K. |last5=Raghothaman |first5=Mukund |last6=Seshia |first6=Sanjit A. |last7=Singh |first7=Rishabh |last8=Solar-Lezama |first8=Armando |last9=Torlak |first9=Emina |author9-link=Emina Torlak|year=2013 |isbn=9780983567837 |pages=1–8 |chapter=Syntax-guided synthesis |citeseerx=10.1.1.377.2829 |doi=10.1109/fmcad.2013.6679385 |last10=Udupa |first10=Abhishek}}</ref>
SearchRepair<ref name="searchrepair">{{Cite book |last1=Ke |first1=Yalin |title=Proceedings of the 2015 30th IEEE/ACM International Conference on Automated Software Engineering |last2=Stolee |first2=Kathryn |last3=Le Goues |first3=Claire |last4=Brun |first4=Yuriy |date=2015 |publisher=ACM |isbn=978-1-5090-0025-8 |series=ASE 2015 |___location=Lincoln, Nebraska |pages=295–306 |chapter=Repairing Programs with Semantic Code Search |doi=10.1109/ASE.2015.60 |s2cid=16361458}}</ref> converts potential patches into an SMT formula and queries candidate patches that allow the patched program to pass all supplied test cases.
Line 38 ⟶ 35:
=== Data-driven ===
[[Machine learning]] techniques can improve the effectiveness of automatic bug-fixing systems.<ref name="prophet" /> One example of such techniques learns from past successful patches from human developers collected from [[open-source software|open source]] [[software repository|repositories]] in [[GitHub]] and [[SourceForge]].<ref name="prophet" /> It then use the learned information to recognize and prioritize potentially correct patches among all generated candidate patches.<ref name="prophet" /> Alternatively, patches can be directly mined from existing sources. Example approaches include mining patches from donor applications<ref name="codephage" /> or from QA web sites.<ref name="QAFix" /
Getafix<ref name=":0">{{Cite journal |last1=Bader |first1=Johannes |last2=Scott |first2=Andrew |last3=Pradel |first3=Michael |last4=Chandra |first4=Satish |date=2019-10-10 |title=Getafix: learning to fix bugs automatically |journal=Proceedings of the ACM on Programming Languages |volume=3 |issue=OOPSLA |pages=159:1–159:27 |doi=10.1145/3360585|doi-access=free }}</ref> is a language-agnostic approach developed and used in production at [[Facebook, Inc.|Facebook]]. Given a sample of [[Commit (version control)|code commits]] where engineers fixed a certain kind of bug, it learns human-like fix patterns that apply to future bugs of the same kind. Besides using Facebook's own [[Repository (version control)|code repositories]] as training data, Getafix learnt some fixes from [[open source]] Java repositories. When new bugs get detected, Getafix applies its previously learnt patterns to produce candidate fixes and ranks them within seconds. It presents only the top-ranked fix for final validation by tools or an engineer, in order to save resources and ideally be so fast that no human time was spent on fixing the same bug, yet.
Line 48 ⟶ 43:
* [[null pointer exception]] repair<ref name="rcv">{{Cite book |last1=Long |first1=Fan |title=Proceedings of the 35th ACM SIGPLAN Conference on Programming Language Design and Implementation |last2=Sidiroglou-Douskos |first2=Stelios |last3=Rinard |first3=Martin |date=2014 |publisher=ACM |isbn=978-1-4503-2784-8 |series=PLDI '14' |___location=New York, New York |pages=227–238 |chapter=Automatic Runtime Error Repair and Containment via Recovery Shepherding |doi=10.1145/2594291.2594337 |s2cid=6252501}}</ref><ref name="nullfix">{{Cite book |last1=Dobolyi |first1=Kinga |title=2008 19th International Symposium on Software Reliability Engineering (ISSRE) |last2=Weimer |first2=Westley |year=2008 |pages=47–56 |chapter=Changing Java's Semantics for Handling Null Pointer Exceptions |citeseerx=10.1.1.147.6158 |doi=10.1109/ISSRE.2008.59 |s2cid=1454939}}</ref><ref name="par">{{Cite book |last1=Kim |first1=Dongsun |title=Proceedings of the 2013 International Conference on Software Engineering |last2=Nam |first2=Jaechang |last3=Song |first3=Jaewoo |last4=Kim |first4=Sunghun |date=2013 |publisher=IEEE Press |isbn=978-1-4673-3076-3 |series=ICSE '13' |pages=802–811 |chapter=Automatic Patch Generation Learned from Human-written Patches}}</ref> with insertion of a [[Conditional (computer programming)|conditional statement]] to check whether the value of a variable is null.
* [[integer overflow]] repair<ref name="codephage">{{Cite book |last1=Sidiroglou |first1=Stelios |title=Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation |last2=Lahtinen |first2=Eric |last3=Long |first3=Fan |last4=Rinard |first4=Martin |date=2015 |chapter=Automatic Error Elimination by Multi-Application Code Transfer
* [[buffer overflow]] repair<ref name="codephage" />
* [[memory leak]] repair,<ref name="leakfix">{{Cite book |last1=Gao |first1=Qing |title=Proceedings of the 37th International Conference on Software Engineering – Volume 1 |last2=Xiong |first2=Yingfei |last3=Mi |first3=Yaqing |last4=Zhang |first4=Lu |last5=Yang |first5=Weikun |last6=Zhou |first6=Zhaoping |last7=Xie |first7=Bing |last8=Mei |first8=Hong |date=2015 |publisher=IEEE Press |isbn=978-1-4799-1934-5 |series=ICSE '15' |___location=Piscataway, New Jersey |pages=459–470 |chapter=Safe Memory-leak Fixing for C Programs}}</ref> with automated insertion of missing memory deallocation statements.
Comparing to generate-and-validate techniques, template-based techniques tend to have better bug-fixing accuracy but a much narrowed scope.<ref name="kali" /><ref name="leakfix" />
Line 59 ⟶ 53:
There are multiple uses of automatic bug fixing:
* In a development environment: When encountering a bug the developer activates a feature to search for a patch (for instance by clicking on a button). This search can also happen in the background, when the IDE proactively searches for solutions to potential problems, without waiting for explicit action from the developer.<ref>{{Cite journal |last1=Muşlu |first1=Kıvanç |last2=Brun |first2=Yuriy |last3=Holmes |first3=Reid |last4=Ernst |first4=Michael D. |last5=Notkin |first5=David |last6=Muşlu |first6=Kıvanç |last7=Brun |first7=Yuriy |last8=Holmes |first8=Reid |last9=Ernst |first9=Michael D. |last10=Notkin |first10=David |date=19 October 2012 |title=Speculative analysis of integrated development environment recommendations, Speculative analysis of integrated development environment recommendations |journal=ACM SIGPLAN Notices |volume=47 |issue=10 |pages=669, 669–682, 682 |citeseerx=10.1.1.259.6341 |doi=10.1145/2384616.2384665 |issn=0362-1340 |s2cid=5795141}}</ref>
* At runtime: When a failure happens at runtime, a binary patch can be searched for and [[Self-modifying code|applied online]]. An example of such a repair system is ClearView,<ref name="clearview">{{Cite book |last=Perkins |first=Jeff H. |title=Proceedings of the ACM SIGOPS 22nd symposium on Operating systems principles |date=2009 |publisher=ACM |isbn=978-1-60558-752-3 |pages=87–102 |chapter=Automatically patching errors in deployed software |citeseerx=10.1.1.157.5877 |doi=10.1145/1629575.1629585 |display-authors=etal |s2cid=7597529}}</ref> which does repair on x86 code, with x86 binary patches.
== Search space ==
In essence, automatic bug fixing is a search activity, whether deductive-based or heuristic-based. The search space of automatic bug fixing is composed of all edits that can be possibly made to a program. There have been studies to understand the structure of this search space. Qi et al.<ref>{{Cite book |last1=Qi |first1=Yuhua |title=The strength of random search on automated program repair |last2=Mao |first2=Xiaoguang |last3=Lei |first3=Yan |last4=Dai |first4=Ziying |last5=Wang |first5=Chengsong |date=2014-05-31 |publisher=ACM |isbn=9781450327565 |pages=254–265 |doi=10.1145/2568225.2568254 |s2cid=14976851}}</ref> showed that the original fitness function of Genprog is not better than random search to drive
== Overfitting ==
Sometimes, in test-suite based program repair, tools generate patches that pass the test suite, yet are actually incorrect, this is known as the "overfitting" problem.<ref name="overfitting">{{Cite book |last1=Smith |first1=Edward K. |title=Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering |last2=Barr |first2=Earl T. |last3=Le Goues |first3=Claire |last4=Brun |first4=Yuriy |date=2015 |publisher=ACM |isbn=978-1-4503-3675-8 |series=ESEC/FSE 2015 |___location=New York, New York |pages=532–543 |chapter=Is the Cure Worse Than the Disease? Overfitting in Automated Program Repair |doi=10.1145/2786805.2786825 |s2cid=6300790}}</ref> "Overfitting" in this context refers to the fact that the patch overfits to the test inputs. There are different kinds of overfitting:
One way to avoid overfitting is to filter out the generated patches. This can be done based on dynamic analysis
== Limitations of automatic bug-fixing ==
Line 90 ⟶ 78:
In C, the Manybugs benchmark collected by GenProg authors contains 69 real world defects and it is widely used to evaluate many other bug-fixing tools for C.<ref name=genprog2012 /><ref name=prophet /><ref name=spr /><ref name=angelix />
In Java, the main benchmark is Defects4J
== Example tools ==
Line 111 ⟶ 99:
* PAR:<ref name=par /> A generate-and-validate tool that uses a set of manually defined fix templates. A later study raised concerns about the generalizability of the fix templates in PAR.<ref name=criticalreview />
* QACrashFix:<ref name="QAFix">{{Cite book |last1=Gao |first1=Qing |title=2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE) |last2=Zhang |first2=Hansheng |last3=Wang |first3=Jie |last4=Xiong |first4=Yingfei |last5=Zhang |first5=Lu |last6=Mei |first6=Hong |date=2015 |publisher=IEEE |isbn=978-1-5090-0025-8 |pages=307–318 |chapter=Fixing Recurring Crash Bugs via Analyzing Q&A Sites |doi=10.1109/ASE.2015.81 |s2cid=2513924}}</ref> A tool that fixes Java crash bugs by mining fixes from Q&A web site.
* ARJA:<ref name="arja">{{Cite journal |last1=Yuan |first1=Yuan |last2=Banzhaf |first2=Wolfgang |date=2020 |title=ARJA: Automated Repair of Java Programs via Multi-Objective Genetic Programming |url=https://doi.org/10.1109/TSE.2018.2874648 |journal=IEEE Transactions on Software Engineering |volume=46 |issue=10 |pages=1040–1067 |arxiv=1712.07804 |doi=10.1109/TSE.2018.2874648|s2cid=25222219 }}</ref> A repair tool for Java based on multi-objective genetic programming.
* NpeFix:<ref name="npefix">{{Cite book |last=Durieux |first=Thomas |title=2017 IEEE 24th International Conference on Software Analysis, Evolution and Reengineering (SANER) |date=2017 |isbn=978-1-5090-5501-2 |pages=349–358 |chapter=Dynamic Patch Generation for Null Pointer Exceptions Using Metaprogramming |arxiv=1812.00409 |doi=10.1109/SANER.2017.7884635 |s2cid=2736203}}</ref> An automatic repair tool for NullPointerException in Java, available [https://github.com/Spirals-Team/npefix on Github].
|