171
Automatic Patch Generation Learned from Human-Written Patches Dongsun Kim, Jaechang Nam, Jaewoo Song, and Sunghun Kim The Hong Kong University of Science and Technology, China 24 May 2013 the 35th International Conference on Software Engineering (ICSE 2013)

Automatic patch generation learned from human written patches

Embed Size (px)

DESCRIPTION

Dongsun's ICSE 2013 Presentation. ACM SIGSOFT Distinguished Paper Award Winner!

Citation preview

Page 1: Automatic patch generation learned from human written patches

Automatic Patch Generation Learned from Human-Written Patches

Dongsun Kim, Jaechang Nam, Jaewoo Song, and Sunghun KimThe Hong Kong University of Science and Technology, China

24 May 2013

the 35th International Conference on Software Engineering (ICSE 2013)

Page 2: Automatic patch generation learned from human written patches

2

Repair

Page 3: Automatic patch generation learned from human written patches

2

Repair

Page 4: Automatic patch generation learned from human written patches

2

Repair GenProgGenProg

Page 5: Automatic patch generation learned from human written patches

3

GenProg

C. Le Goues, M. Dewey-Vogt, S. Forrest, and W. Weimer, “A systematic study of automated program repair: Fixing 55 out of 105 bugs for $8 each,” in ICSE ’12.

Page 6: Automatic patch generation learned from human written patches

3

GenProgState-of-the-art

C. Le Goues, M. Dewey-Vogt, S. Forrest, and W. Weimer, “A systematic study of automated program repair: Fixing 55 out of 105 bugs for $8 each,” in ICSE ’12.

Page 7: Automatic patch generation learned from human written patches

3

GenProgState-of-the-artGenetic Programming

C. Le Goues, M. Dewey-Vogt, S. Forrest, and W. Weimer, “A systematic study of automated program repair: Fixing 55 out of 105 bugs for $8 each,” in ICSE ’12.

Page 8: Automatic patch generation learned from human written patches

3

GenProgState-of-the-artGenetic ProgrammingRandom Mutation

C. Le Goues, M. Dewey-Vogt, S. Forrest, and W. Weimer, “A systematic study of automated program repair: Fixing 55 out of 105 bugs for $8 each,” in ICSE ’12.

Page 9: Automatic patch generation learned from human written patches

3

GenProgState-of-the-artGenetic ProgrammingRandom MutationSystematically Evaluated

C. Le Goues, M. Dewey-Vogt, S. Forrest, and W. Weimer, “A systematic study of automated program repair: Fixing 55 out of 105 bugs for $8 each,” in ICSE ’12.

Page 10: Automatic patch generation learned from human written patches

4

Buggy Code

Page 11: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

4

in Interpreter.java reported as Mozilla Bug #76683

Buggy Code

Page 12: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

4

in Interpreter.java reported as Mozilla Bug #76683

Buggy Code

Page 13: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

4

in Interpreter.java reported as Mozilla Bug #76683

Null Pointer Exception

Buggy Code

Page 14: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

5

GenProg repairs bugs

Page 15: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

5

GenProg repairs bugs

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Buggy  Code

GenProg

Page 16: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

5

GenProg repairs bugs

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Buggy  Code

GenProg

Page 17: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

5

GenProg repairs bugs

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Buggy  Code

GenProg

This patch passes ALL test cases.

Page 18: Automatic patch generation learned from human written patches

6

GenProg repairs bugs1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

Page 19: Automatic patch generation learned from human written patches

6

GenProg repairs bugs1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

Page 20: Automatic patch generation learned from human written patches

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

6

GenProg repairs bugs1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�deleted.�1507� }�1508� state.parenCount�=�num;�

Page 21: Automatic patch generation learned from human written patches

7

Would you accept?

Page 22: Automatic patch generation learned from human written patches

7

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�do�nothing.�1507� }�1508� state.parenCount�=�num;�

Would you accept?

Page 23: Automatic patch generation learned from human written patches

7

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�do�nothing.�1507� }�1508� state.parenCount�=�num;�

Would you accept?

Page 24: Automatic patch generation learned from human written patches

7

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�do�nothing.�1507� }�1508� state.parenCount�=�num;�

Would you accept?

17  Students68  Developers

Page 25: Automatic patch generation learned from human written patches

8

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�do�nothing.�1507� }�1508� state.parenCount�=�num;�

Would you accept?

17  Students68  Developers

Page 26: Automatic patch generation learned from human written patches

8

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502 ����� � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� {�1506� � //�do�nothing.�1507� }�1508� state.parenCount�=�num;�

Would you accept?

9.4%

90.6%17  Students68  Developers

Page 27: Automatic patch generation learned from human written patches

9

Page 28: Automatic patch generation learned from human written patches

9

Page 29: Automatic patch generation learned from human written patches

9

•Random

Page 30: Automatic patch generation learned from human written patches

9

•Random•Unnatural

Page 31: Automatic patch generation learned from human written patches

9

•Random•Unnatural•Harder  to  understand

Page 32: Automatic patch generation learned from human written patches

10

Page 33: Automatic patch generation learned from human written patches

10

Page 34: Automatic patch generation learned from human written patches

10

RandomEvolution

Page 35: Automatic patch generation learned from human written patches

10

RandomEvolution

Explores the large search space

Page 36: Automatic patch generation learned from human written patches

10

RandomEvolution

Explores the large search spacebut sometimes

producesrandom results

Page 37: Automatic patch generation learned from human written patches

10

RandomEvolution

IntelligentDesign

Explores the large search spacebut sometimes

producesrandom results

Page 38: Automatic patch generation learned from human written patches

10

RandomEvolution

IntelligentDesign

Explores the large search space Leverages human

knowledgebut sometimes produces

random results

Page 39: Automatic patch generation learned from human written patches

11

Human-written Patches

Page 40: Automatic patch generation learned from human written patches

11

Human-written PatchesReadable

Page 41: Automatic patch generation learned from human written patches

11

Human-written PatchesReadableNatural

Page 42: Automatic patch generation learned from human written patches

11

Human-written PatchesReadableNaturalEasy to understand

Page 43: Automatic patch generation learned from human written patches

11

Human-written PatchesReadableNaturalEasy to understand

We can learn how to generate patches from human knowledge.

Page 44: Automatic patch generation learned from human written patches

12

Page 45: Automatic patch generation learned from human written patches

12

JDT

Page 46: Automatic patch generation learned from human written patches

12

>60,000Patches

JDT

Page 47: Automatic patch generation learned from human written patches

12

ManualClassification

>60,000Patches

JDT

Page 48: Automatic patch generation learned from human written patches

12

ManualClassification

# p

atch

es

Patterns

>60,000Patches

JDT

Page 49: Automatic patch generation learned from human written patches

12

ManualClassification

# p

atch

es

Patterns

>60,000Patches

JDT

Page 50: Automatic patch generation learned from human written patches

12

ManualClassification

# p

atch

es

Patterns

Top frequent patterns account for >20~30%

>60,000Patches

JDT

Page 51: Automatic patch generation learned from human written patches

13

Common Fix PatternsAltering method parameters

obj.method(v1,v2)0→0obj.method(v1,v3)

Altering method parameters

obj.method(v1,v2)0→0obj.method(v1,v3)

Page 52: Automatic patch generation learned from human written patches

13

Common Fix PatternsAdding a checker

obj.m1())→)if(obj'!='null)){obj.m1()}

Adding a checker

obj.m1())→)if(obj'!='null)){obj.m1()}

Page 53: Automatic patch generation learned from human written patches

14

PAR

Pattern-based Automatic Program Repair

Page 54: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

15

Page 55: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

15

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Human Knowledge

Page 56: Automatic patch generation learned from human written patches

16

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Using Human Knowledge

for patch generation

Page 57: Automatic patch generation learned from human written patches

16

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix Templates

Using Human Knowledge

for patch generation

Page 58: Automatic patch generation learned from human written patches

16

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix TemplatesProgram Edit Script

Using Human Knowledge

for patch generation

Page 59: Automatic patch generation learned from human written patches

16

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix TemplatesProgram Edit Script

Using Human Knowledge

for patch generation

10

Page 60: Automatic patch generation learned from human written patches

16

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix TemplatesProgram Edit Script

Manually created from fix patterns

Using Human Knowledge

for patch generation

10

Page 61: Automatic patch generation learned from human written patches

16

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix TemplatesProgram Edit Script

Manually created from fix patternsHighly reusable

Using Human Knowledge

for patch generation

10

Page 62: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

17

Page 63: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

18

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Fault Localization

Page 64: Automatic patch generation learned from human written patches

19

Fault Locations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 65: Automatic patch generation learned from human written patches

19

TP TF

Fault Locations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 66: Automatic patch generation learned from human written patches

19

TP TF

Fault Locations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 67: Automatic patch generation learned from human written patches

19

TP TF

Fault Locations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 68: Automatic patch generation learned from human written patches

19

TP TF

Fault Locations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 69: Automatic patch generation learned from human written patches

19

TP TF

Fault Locations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 70: Automatic patch generation learned from human written patches

19

TP TF

Fault Locations

Faultlocations

J. A. Jones, M. J. Harrold, and J. Stasko, “Visualization of test information to assist fault localization,” in Proceedings of the 24th International Conference on Software Engineering, New York, NY, USA, 2002, pp. 467–477.

Page 71: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

20

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Fault Localization

Page 72: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

21

Page 73: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

22

Template-basedPatch Candidate Generation

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

Fix Template

Patch Candidate

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMON

Fault Location

Page 74: Automatic patch generation learned from human written patches

23

How a Fix Template works

Page 75: Automatic patch generation learned from human written patches

23

How a Fix Template works

Page 76: Automatic patch generation learned from human written patches

23

How a Fix Template works

Page 77: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

23

How a Fix Template works

Page 78: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

23

How a Fix Template works

Page 79: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

23

How a Fix Template works

Page 80: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

23

AST Analysis→Collects necessary AST nodes

How a Fix Template works

Page 81: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

23

AST Analysis→Collects necessary AST nodes

Context Check→Examines applicability

How a Fix Template works

Page 82: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

23

AST Analysis→Collects necessary AST nodes

Context Check→Examines applicability

Program Editing→Modifies the source code

How a Fix Template works

Page 83: Automatic patch generation learned from human written patches

Using a Fix Template: An Example

24

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 84: Automatic patch generation learned from human written patches

Using a Fix Template: An Example

24

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 85: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 86: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

obj ref.: state, parens[i], ...

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 87: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

obj ref.: state, parens[i], ...

Check obj ref.: PASS

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 88: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

obj ref.: state, parens[i], ...

Check obj ref.: PASS

Edit: Insert ... ... + if( ) { state.parens[i].length = 0; + } ... ...

state != null && state.parens[i] != null

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 89: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

obj ref.: state, parens[i], ...

Check obj ref.: PASS

Edit: Insert ... ... + if( ) { state.parens[i].length = 0; + } ... ...

state != null && state.parens[i] != null

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 90: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

obj ref.: state, parens[i], ...

Check obj ref.: PASS

Edit: Insert ... ... + if( ) { state.parens[i].length = 0; + } ... ...

state != null && state.parens[i] != null

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 state.parens[i].length = 0; 1506 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 { 1506 // deleted. 1507 } 1508 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 state.parens[i].length = 0; 1506 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 { 1506 if( state != null && state.parens[i] != null) 1507 state.parens[i].length = 0; 1508 } 1509 state.parenCount = num;

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 91: Automatic patch generation learned from human written patches

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+Null Pointer Checker

Using a Fix Template: An Example

24

obj ref.: state, parens[i], ...

Check obj ref.: PASS

Edit: Insert ... ... + if( ) { state.parens[i].length = 0; + } ... ...

state != null && state.parens[i] != null

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 state.parens[i].length = 0; 1506 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 { 1506 // deleted. 1507 } 1508 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 state.parens[i].length = 0; 1506 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 { 1506 if( state != null && state.parens[i] != null) 1507 state.parens[i].length = 0; 1508 } 1509 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 state.parens[i].length = 0; 1506 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 { 1506 // deleted. 1507 } 1508 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 state.parens[i].length = 0; 1506 state.parenCount = num;

1500 num = state.parenCount; 1501 int kidMatch = matchRENodes(state, (RENode)ren.kid, 1502 stop, index); 1503 if (kidMatch != -1) return kidMatch; 1504 for (int i = num; i < state.parenCount; i++) 1505 { 1506 if( state != null && state.parens[i] != null) 1507 state.parens[i].length = 0; 1508 } 1509 state.parenCount = num;

1500� num�=�state.parenCount;�1501� int�kidMatch�=�matchRENodes(state,�(RENode)ren.kid,�1502������ � � � � stop,�index);�1503� if�(kidMatch�!=�Ş1)�return�kidMatch;�1504� for�(int�i�=�num;�i�<�state.parenCount;�i++)�1505� � state.parens[i].length�=�0;�1506� state.parenCount�=�num;�

Page 92: Automatic patch generation learned from human written patches

25

List of Templates

Page 93: Automatic patch generation learned from human written patches

25

List of Templates

Parameter Replacer

Method Replacer

Parameter Adder and Remover

Expression Replacer

Expression Adder and Remover

Object Initializer

Range Checker

Collection Size Checker

Null Pointer Checker

Class Cast Checker

Page 94: Automatic patch generation learned from human written patches

26

Creating Patch Candidates

Page 95: Automatic patch generation learned from human written patches

26

Creating Patch Candidates

Page 96: Automatic patch generation learned from human written patches

26

Fault location #1

Fault location #2

Fault location #3

Fault location #4

Fault location #N

...

Creating Patch Candidates

Page 97: Automatic patch generation learned from human written patches

26

Fault location #1

Fault location #2

Fault location #3

Fault location #4

Fault location #N

...

Creating Patch Candidates

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

...$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix Templates

Page 98: Automatic patch generation learned from human written patches

26

Fault location #1

Fault location #2

Fault location #3

Fault location #4

Fault location #N

...

Creating Patch Candidates

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

...$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

Fix Templates

...

PatchCandidates

Page 99: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

27

Template-basedPatch Candidate Generation

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

Fix Template

Patch Candidate

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMON

Fault Location

Page 100: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

28

Patch Evaluation

Page 101: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

Page 102: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

T Repaired

TestCases

Page 103: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

T Repaired

TestCases

Page 104: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

T Repaired

PassTestCases

Page 105: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

T Repaired

T Repaired

PassTestCases

Page 106: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

T Repaired

T Repaired

Pass

Fail

TestCases

Page 107: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

29

Patch Evaluation

T Repaired

T Repaired

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

Fix Template

Patch Candidate

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMON

Fault Location

Pass

Fail

TestCases

Page 108: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

30

Page 109: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

30

Page 110: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

30

Page 111: Automatic patch generation learned from human written patches

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

30

Page 112: Automatic patch generation learned from human written patches

31

Evaluation: Experiment Design

Page 113: Automatic patch generation learned from human written patches

31

Evaluation: Experiment Design

Page 114: Automatic patch generation learned from human written patches

31

Evaluation: Experiment Design

PAR GenPro

Page 115: Automatic patch generation learned from human written patches

31

Evaluation: Experiment Design

PAR GenPro

Page 116: Automatic patch generation learned from human written patches

31

Evaluation: Experiment Design

PAR GenPro

Page 117: Automatic patch generation learned from human written patches

31

Evaluation: Experiment Design

PAR GenPro

# #

Page 118: Automatic patch generation learned from human written patches

32

RQ1(Fixability): How many bugs are fixed successfully?

RQ2(Acceptability): Which approach can generate more acceptable bug patches?

Evaluation: Research Questions

#

Page 119: Automatic patch generation learned from human written patches

33

Subject # bugs LOC # test cases

Rhino 17 51,001 5,578

AspectJ 18 180,394 1,602

log4j 15 27,855 705

Math 29 121,168 3,538

Lang 20 54,537 2,051

Collections 20 48,049 11,577

Total 119 351,406 25,051

Experiment Subjects

Page 120: Automatic patch generation learned from human written patches

34

RQ1: Fixability

Page 121: Automatic patch generation learned from human written patches

34

RQ1: Fixability

PAR GenProg06

12182430

Page 122: Automatic patch generation learned from human written patches

34

RQ1: Fixability

PAR GenProg06

12182430

27

Page 123: Automatic patch generation learned from human written patches

34

RQ1: Fixability

PAR GenProg06

12182430

27

16

Page 124: Automatic patch generation learned from human written patches

34

RQ1: Fixability

PAR GenProg06

12182430

27

16PAR GenProg

27 16>

Page 125: Automatic patch generation learned from human written patches

35

RQ2: Acceptability

Page 126: Automatic patch generation learned from human written patches

35

RQ2: Acceptability

User Study #1: Ranking between PAR and GenProg

Page 127: Automatic patch generation learned from human written patches

36

Page 128: Automatic patch generation learned from human written patches

36

PAR

Page 129: Automatic patch generation learned from human written patches

36

PAR GenProg

Page 130: Automatic patch generation learned from human written patches

36

PAR GenProg

5

Page 131: Automatic patch generation learned from human written patches

37

User Study #1Ranking Patches

Page 132: Automatic patch generation learned from human written patches

37

User Study #1Bug DescriptionRanking Patches

Page 133: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Ranking Patches

Page 134: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Anonymized Patch #1

Ranking Patches

Page 135: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Ranking Patches

Page 136: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Anonymized Patch #3

Ranking Patches

Page 137: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Anonymized Patch #3

Ranking Patches

Page 138: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Anonymized Patch #3

Rank patches

17  Students68  Developers

Ranking Patches

Page 139: Automatic patch generation learned from human written patches

37

User Study #1Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Anonymized Patch #3

2

1

3

Rank patches

17  Students68  Developers

Ranking Patches

Page 140: Automatic patch generation learned from human written patches

User Study #1: ResultsStudent  group  (avg.  ranking)

38

(the lower the better)Developer  group  (avg.  ranking)

(the lower the better)

Page 141: Automatic patch generation learned from human written patches

User Study #1: ResultsStudent  group  (avg.  ranking)

38

0

0.75

1.5

2.25

3

1.72 1.57

2.67

PAR GenProgHuman

(the lower the better)Developer  group  (avg.  ranking)

(the lower the better)

Page 142: Automatic patch generation learned from human written patches

User Study #1: ResultsStudent  group  (avg.  ranking)

38

0

0.75

1.5

2.25

3

1.72 1.57

2.67

PAR GenProgHuman

(the lower the better)Developer  group  (avg.  ranking)

(the lower the better)

SignificantlyDifferent

Page 143: Automatic patch generation learned from human written patches

User Study #1: ResultsStudent  group  (avg.  ranking)

38

0

0.75

1.5

2.25

3

1.72 1.57

2.67

PAR GenProgHuman

(the lower the better)Developer  group  (avg.  ranking)

1

1.35

1.7

2.05

2.4

1.81 1.82

2.36

(the lower the better)

PARGenPro

gHuman

SignificantlyDifferent

Page 144: Automatic patch generation learned from human written patches

User Study #1: ResultsStudent  group  (avg.  ranking)

38

0

0.75

1.5

2.25

3

1.72 1.57

2.67

PAR GenProgHuman

(the lower the better)Developer  group  (avg.  ranking)

1

1.35

1.7

2.05

2.4

1.81 1.82

2.36

(the lower the better)

PARGenPro

gHuman

SignificantlyDifferent

SignificantlyDifferent

Page 145: Automatic patch generation learned from human written patches

User Study #1: ResultsStudent  group  (avg.  ranking)

38

0

0.75

1.5

2.25

3

1.72 1.57

2.67

PAR GenProgHuman

(the lower the better)Developer  group  (avg.  ranking)

1

1.35

1.7

2.05

2.4

1.81 1.82

2.36

(the lower the better)

PARGenPro

gHuman

SignificantlyDifferent

SignificantlyDifferentPAR generates better ranking

patches than GenProg

Page 146: Automatic patch generation learned from human written patches

39

RQ2: Acceptability

User Study #1: Ranking between PAR and GenProg

Page 147: Automatic patch generation learned from human written patches

39

RQ2: Acceptability

User Study #1: Ranking between PAR and GenProg

User Study #2: Pair-wise Comparison between

Human-written PatchesVs.

PAR or GenProg

Page 148: Automatic patch generation learned from human written patches

40

Page 149: Automatic patch generation learned from human written patches

40

PAR

27

Page 150: Automatic patch generation learned from human written patches

40

PAR

27

GenProg

16

Page 151: Automatic patch generation learned from human written patches

41

User Study #2Pair-wise Comparison

Page 152: Automatic patch generation learned from human written patches

41

User Study #2Bug DescriptionPair-wise Comparison

Page 153: Automatic patch generation learned from human written patches

41

User Study #2Bug Description

Buggy Code

Pair-wise Comparison

Page 154: Automatic patch generation learned from human written patches

41

User Study #2Bug Description

Buggy Code

Anonymized Patch #1

Pair-wise Comparison

Page 155: Automatic patch generation learned from human written patches

41

User Study #2Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Pair-wise Comparison

Page 156: Automatic patch generation learned from human written patches

41

User Study #2Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Choose acceptablepatch(es)

72  Students96  Developers

Pair-wise Comparison

Page 157: Automatic patch generation learned from human written patches

41

User Study #2Bug Description

Buggy Code

Anonymized Patch #1

Anonymized Patch #2

Patch #1 Patch #2

Both Not sure

Choose acceptablepatch(es)

72  Students96  Developers

Pair-wise Comparison

Page 158: Automatic patch generation learned from human written patches

User Study #2: Results

GenProg

42

PAR

Page 159: Automatic patch generation learned from human written patches

User Study #2: Results

GenProg

42

0

10

20

30

40

21

28

37

14resp

onse

s (%

)

PAR HumanBoth NotSure

PAR

Page 160: Automatic patch generation learned from human written patches

User Study #2: Results

GenProg

42

0

10

20

30

40

21

28

37

14resp

onse

s (%

)

PAR HumanBoth NotSure

PAR

0

15

30

45

60

20

12

51

17re

spon

ses

(%)

GenProg HumanBoth NotSure

Page 161: Automatic patch generation learned from human written patches

User Study #2: Results

GenProg

42

0

10

20

30

40

21

28

37

14resp

onse

s (%

)

PAR HumanBoth NotSure

PAR

0

15

30

45

60

20

12

51

17re

spon

ses

(%)

GenProg HumanBoth NotSure

49%

Page 162: Automatic patch generation learned from human written patches

User Study #2: Results

GenProg

42

0

10

20

30

40

21

28

37

14resp

onse

s (%

)

PAR HumanBoth NotSure

PAR

0

15

30

45

60

20

12

51

17re

spon

ses

(%)

GenProg HumanBoth NotSure

49%

32%

Page 163: Automatic patch generation learned from human written patches

User Study #2: Results

GenProg

42

0

10

20

30

40

21

28

37

14resp

onse

s (%

)

PAR HumanBoth NotSure

PAR

0

15

30

45

60

20

12

51

17re

spon

ses

(%)

GenProg HumanBoth NotSure

49%

32%PAR generates more

acceptable patches than GenProg

Page 164: Automatic patch generation learned from human written patches

43

Limitations

• Fix templates are written manually.• But it is one-time cost, these are highly reusable.

• We entirely re-implemented GenProg by Java.

• All subjects are collected from open source projects.

• Some participants may not be thoroughly qualified.

Page 165: Automatic patch generation learned from human written patches

44

Summary

Page 166: Automatic patch generation learned from human written patches

44

Summary

Observed common patches

# p

atch

es

Patterns

Page 167: Automatic patch generation learned from human written patches

44

Summary

Observed common patches

# p

atch

es

Patterns

Fix Templates and PARif(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

Page 168: Automatic patch generation learned from human written patches

44

Summary

Can fix more bugs with more acceptability

Observed common patches

# p

atch

es

Patterns

Fix Templates and PARif(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

0

6

12

18

24

30

16

27

0

0.75

1.5

2.25

3

1

1.35

1.7

2.05

2.4

0

10

20

30

40

PAR HumanBoth NotSure

0

15

30

45

60

GenProg HumanBoth NotSure

49%

32%

Page 169: Automatic patch generation learned from human written patches

45

Future Work

Automatic Fix Template Identification• More templates can fix more bugs.

More Test Cases• More test cases may lead us to better patches.

Page 170: Automatic patch generation learned from human written patches

46

Acknowledgement

Special Thanks to:

Westley Weimer, Claire Le Goues,

Thomas Zimmermann, and Christian Bird

Page 171: Automatic patch generation learned from human written patches

47

Summary

Fix Templates and PAR

Can fix more bugs with more acceptability

Observed common patches

# p

atch

es

Patterns

if(lhs == DBL_MRK) lhs = ...; if(lhs == undefined) { lhs = strings[pc + 1]; } Scriptable calleeScope = ...;

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Buggy Program

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

(a) Fault Localization

$VJDGVIDVGIDVOGMJONDMDVJDGI��O+6GOMNIONDVMGI�OMDVGOIMVGO-GVIVDGIVGDIVGDVGONIMGDVOM+

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO-++

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

GVIVDGIVGDIVGDVGONIMGDVOM

(b) Template-based Patch Candidate Generation

Fail

Pass

(c) Patch Evaluation

T Repaired

Fix Template

Patch Candidate

VGDJNOMODNZMHIUOZMHIVGMON�

DDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

VGDJNOMODNZMHIUOZMHIVGMONDDKOMDOMODMIO�GVNOMKVGONMIGVDI

$VJDGVIDVGIDVOGMJONDMDVJDGI��O

6GOMNIONDVMGI�OMDVGOIMVGO

GVIVDGIVGDIVGDVGONIMGDVOM

ONDVMIONMVGDONIMOGNVDMIONGVDM

Repaired Program

Fault Location

0

6

12

18

24

30

16

27

0

0.75

1.5

2.25

3

1

1.35

1.7

2.05

2.4

0

10

20

30

40

PAR HumanBoth NotSure

0

15

30

45

60

GenProg HumanBoth NotSure

49%

32%