an empirical investigation into the role of api-level...

33
An Empirical Investigation into the Role of API-Level Refactorings during Software Evolution KAIST SE LAB 2013 International Conference on Software Engineering (2011) Miryung Kim, Dongxiang Cai, Sunghun Kim 2013-09-10 Yoo Jin Lim

Upload: nguyenthien

Post on 01-Sep-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

An Empirical Investigation into the Role of API-Level Refactorings

during Software Evolution

ⓒ KAIST SE LAB 2013

International Conference on Software Engineering(2011)

Miryung Kim, Dongxiang Cai, Sunghun Kim

2013-09-10Yoo Jin Lim

Page 2: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Contents

IntroductionRelated WorkOverall ApproachStudy ApproachResultsResults OverviewConclusionDiscussion

2/24 ⓒ KAIST SE LAB 2013

Page 3: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Refactoring Changes program’s internal structure without modifying its external

functional behavior Improves software quality in software evolution

• Making it easier to understand, maintain, and modify software

API-level refactoring• Rename• Move• Signature changes

Introduction (1/3)

3/27ⓒ KAIST SE LAB 2013

package Pclass C

method(par1, par2) {//*** Body ***//}

Page 4: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Introduction (2/3) Hypotheses (Questions) about API-level Refactoring

4/27ⓒ KAIST SE LAB 2013

H1: There are more bug fixes afterwards. Does the bug fix rate increase after refactorings?

H2: Refactoring improves developer’s productivity. Does the bug fix time decrease after refactorings?

H3: If H1&2 are true, refactoring facilitates bug fixes. Is a large number of refactoring revisions also including bug fixes or related to later bug fixes?

H4: Developers avoid it if under time constraints. Are there relatively fewer refactorings before major software release dates?

Page 5: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Introduction (3/3)Motivation

The role of refactorings during software evolution has not been systematically investigated

• Questions remain as to the true benefits of refactorings in terms of bug fixing and developer productivity.

Goal Investigate the role of refactorings, using fine-grained revision

history at the method level.• Examine the relationships between API-level refactorings, bug fixes,

the time to resolve bugs, and release cycles.

5/27ⓒ KAIST SE LAB 2013

Page 6: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Related Work

Weiβgeber & Diehl(2006)

Ratzinger et al. (2008)

Focus Relationship between refactorings and bugs

Relationship between refactorings and bugs

AnalysisMethod

Use N-day time window Use time periods

Result Number of bugs increasesafter refactorings

Number of bugs decreasesafter refactorings

6/27ⓒ KAIST SE LAB 2013

This Study (Kim et al.) Focus: Relationship between API-level refactorings and bug fixes

• bug fixes, bug fix times, and release cycles. Method: Use K-revision sliding window and method-level locations

• examine their relationship more accurately

Page 7: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Overall Approach

7/27ⓒ KAIST SE LAB 2013

Q1: Are there more bug fixes after API-level refactorings?

Q3: Do refactorings facilitate bug fixes?

Q2: Do refactorings improve productivity?

Q4: Are there relatively fewer before major releases?

Revision History

API-levelRefactoring Revisions

Bug FixRevisions

Bug Fix Time

Change Distilling

Refactoring Reconstruction

Bug HistoryExtraction

API-levelBug Fix

Locations

Page 8: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Study Approach (1/6) Subject programs

Eclipse JDT, jEdit, and Columba• Large open-source software with high quality change logs

Eclipse JDT core jEdit ColumbaType IDE Text editor Email client

Period Jun 2001 – May 2007 Sep 2001 – Apr 2009 Jul 2006 – Jan 2010

# Revisions 15000 11102 421

# Refactoring Revisions 1089 423 36

# Bug Fix Revisions 3752 1073 150

ⓒ KAIST SE LAB 2013 8/27*Adapted from M. Kim’s ppt slides

Page 9: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Study Approach (2/6) Identification of API-level Refactoring Revisions

Automatic refactoring reconstruction technique (M.Kim et al.)• Limited to API-level = changes at or above method header level

9/27ⓒ KAIST SE LAB 2013

Rename

Move

Signaturechange

Version 1 ∆ Version 2 Refactoringrevisionclass X

{int Sub(){…};

int Add(){…};}

class Y{

int Add_one(){…}}

class X{

int Subtract();

}

class Y{

int Add() {…};

int Add_one(int a){…}}

Page 10: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Study Approach (3/6) Identification of Bug Fix Revisions

Bug history extraction technique (S.Kim et al.)• Heuristically mine change log comments for bug fix keywords

10/27ⓒ KAIST SE LAB 2013

Date: 9/1/12Name: AbeLine #’s: 4

…Comment: Changed M1(),

see bug ID#42233

Date: 9/5/12Name: BobLine #’s: 56 ~ 58

…Comment: Updated license

Date: 9/15/12Name: ChoLine #’s: 9

Comment: Fixed M1()

Revision 1.1 Revision 1.2 Revision 1.3

Page 11: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Study Approach (4/6) Identification of Bug-introducing Changes

Tracing back in the revision history (Sliwerski et al.)• Use Diff outputs to track down the origin of flawed change• Identify Bug FixTime in days

11/27

Date: 9/5/12Name: BobLine #’s: 56 ~ 58Comment: Updated license

Revision 1.1 Revision 1.2 Revision 1.3

Date: 9/15/12Name: ChoLine #’s: 9Comment: Fixed M1()

Date: 9/1/12Name: AbeLine #’s: 4Comment: Changed M1(), see bug ID#42233

ⓒ KAIST SE LAB 2013

DiffDiff

Page 12: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Study Approach (5/6) Change Distilling

Map the line-level location of a bug fix to its container method• To compare with API-level refactoring location

12/27ⓒ KAIST SE LAB 2013

Revision 1.1

Date: 9/1/12Name: AbeLine #’s: 4

…Comment: Changed M1(), see bug ID#42233

1 public void Method2()2 {3 … 4 Bug_Fixed(); 5 …6 }

Change Distilling

Page 13: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Study Approach (6/6) Accuracy of MK and SK Techniques

Automated techniques Vs. Manual inspection

13/27ⓒ KAIST SE LAB 2013

Manual Count Source # Prec. Recall

APIRefactoringRevision

14 [MK] API-level refactoring detection 14 0.93 0.93

Inspection of change logs only 2 0.50 0.07

Inspection of bug reports only 5 0.75 0.21

FixRevision

62 [SK] Fix-revision detection 49 0.96 0.76

Inspection of change logs only 55 0.92 0.81

Inspection of bug reports only 49 0.94 0.74

Revision History

Change logsBug reportsDiff outputs

Revision History

~14000

100

Overall, this study’s revision data are accurate enough

14Refactoring Revisions

62Bug Fix

Revisions

Page 14: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Q1: Are there more bug fixes after API-level refactorings? Compute a fix rate, / , within K sliding window

before and after each refactoring revision.

Compute the fix rate for each method.

Method1

Results (1/11)

14/27ⓒ KAIST SE LAB 2013

Fix RefFixTime

Ref FixFixRevisions

Method2

Fix RefFixTime

FixFix

K revision windows K revision windows

Ref

Page 15: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (2/11) Q1: Are there more bug fixes after API-level refactorings?

Fix rates increase after refactorings

15/27ⓒ KAIST SE LAB 2013

AfterBefore

Fix rate at revision level

Refactoring TimingWindow Size (K)

Page 16: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (3/11) Q1: Are there more bug fixes after API-level refactorings?

Fix rates also increase after refactorings at the method level

16/27ⓒ KAIST SE LAB 2013

Fix rate at a

 metho

d level

Refactoring Timing Refactoring Timing Refactoring Timing

There is a short-term increase in the number of bug fixes after refactorings

Page 17: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (4/11)

17/27ⓒ KAIST SE LAB 2013

Types Frequency1 Refactoring with a bug fix is incomplete, inducing a later fix. 50%2 Incorrect refactorings cause a bug, inducing a later fix. 6%3 To fix several related bugs, developer first refactors. 6%4 After refactorings, developer discovers a new bug and fixes it. 2%5 Bug fix happened after refactoring in the same location, but

they are not related.36%

20 revision windows

Method1

one bug fix applied to same method within K=20.

Bugs introduced, which get fixed later Developers helped in identifying bugs

Q1: Are there more bug fixes after API-level refactorings? Find refactoring revisions with at least

Randomly select 50 of them for manual investigation

Page 18: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (5/11) Q2: Do refactorings improve developer productivity?

Estimate time taken to fix bugs near the refactoring timing• Categorized into four classes based on Before and After refactoring

• Calculate time in each category for each refactoring using K = 100

18/27ⓒ KAIST SE LAB 2013

K revisions K revisions

TimeRef

Revisions

K revisions

XB BB BA AA

Bug Fix

Bug Intro

Page 19: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (6/11) Q2: Do refactorings improve developer productivity?

19/27ⓒ KAIST SE LAB 2013

The average fix time tends to decrease after refactorings.

Fix is easier since code is refactored Refactoring mistakes take quick and

easy supplementary fixes

WHY?

Average Fix Time (Days)

Page 20: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (7/11) Q3: Do API-level refactorings facilitate bug fixes?

Are many refactorings done as part of bug fix or related to later fix?• Identify revisions including both refactoring and bug fix

20/27ⓒ KAIST SE LAB 2013

Probability of fixes and refactorings at revision levelSubject P(F) P(R) P(R|F) P(R|not F) P(F|R) P(F|not R)Eclipse JDT 25.0% 7.3% 12.0% 5.7% 41.5% 23.7%JEdit 9.7% 3.8% 11.5% 3.0% 29.1% 8.9%Columba 35.7% 8.6% 10.7% 7.4% 44.4% 34.8%

Fixes and refactorings often appear in the same revision.

Page 21: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (8/11) Q3: Do API-level refactorings facilitate bug fixes?

Are many refactorings done as part of bug fix or related to later fix?• Find refactoring revisions with at least one

21/27ⓒ KAIST SE LAB 2013

Refactoring are followed by related bug fixes more often than non-refactoring.

Refactorings applied to fix hard bugs Refactoring mistakes corrected later

WHY?

# of Ref-revisions related to fix within K=20

# of Non-ref revisions related to fix within K=20

bug fix applied to same method within K=20.

Page 22: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Q4: Are there relatively fewer API-level refactorings before major releases? Measure refactorings rates before and after each release.

• 15 major releases in Eclipse JDT and 4 in jEdit Measure bug fix rates also

Results (9/11)

22/27ⓒ KAIST SE LAB 2013

Major Release

K revision windows = ‐20, ‐30, ‐40 K revision windows = 20, 30, 40

Fix RefFix

Time

Ref FixFix

Page 23: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Q4: Are there relatively fewer API-level refactorings before major releases? Result 1: Bug fix rate

Results (10/11)

23/27ⓒ KAIST SE LAB 2013

No more adding new features Focus on bug fixing

fix ra

tefix

rate

window size (K)

Eclipse JDT

JEdit

window size (K)

Page 24: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Results (11/11) Q4: Are there relatively fewer API-level refactorings before

major releases? Result 2: Refactoring rate

24/27ⓒ KAIST SE LAB 2013

There are more refactorings and bug fixes before major version releases.

Developers apply refactorings to implement bug fixes to be shipped with a new release

WHY?

Ref

acto

ring

rate

window size (K)Eclipse JDT JEdit

window size (K)R

efac

torin

g ra

te

Page 25: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Refactorings occur more frequently before major releases than after.

Results Overview

25/27ⓒ KAIST SE LAB 2013

There is an increase in bug fixes. Bug fix time is shorter.

Q3: Do Refactorings Facilitate Bug Fixes?Motivated to ask

Usually the same developer applies related bug fixes

Refactoring revisions are related to later bug fixes.

Refactoring revisions often include bug fixes at the same time

Q1&2: What happens to Bug Fixes After Refactorings?

Q4: Are there Fewer Before Releases?

Developers apply refactorings to fix hard-to-fix bugs

orapply supplementary fixes later to correct refactoring mistakes.

Developers apply refactorings to implement bug fixes to be shipped with new release.

Page 26: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Conclusion Contributions

Revealed interesting relationships between refactorings and bug fixes

• API-level refactoring serves the role of both facilitating bug fixes and inducing bugs

Future Work Cost-benefit analysis of refactoring investment Development of new tools that correct inconsistent refactorings

26/27ⓒ KAIST SE LAB 2013

Page 27: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Discussion Limitations

Refactoring reconstruction coverage and accuracy• Only captures a small subset of refactorings

Phases and activity levels• K-sliding window method may be an inconsistent map

Development practice• A few developers’ practices may have strongly affected study results

27/27ⓒ KAIST SE LAB 2013

Page 28: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

ⓒ KAIST SE LAB 2013

Page 29: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Appendix

Bug Reports

29/27ⓒ KAIST SE LAB 2013

Page 30: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

… … … 8 :1.0 public int M1(){9 :1.1 return i/0; … … …

Appendix Identification of Bug-introducing Changes

ⓒ KAIST SE LAB 2013

Date: 9/5/12Name: BobLine #’s: 56 ~ 58Comment: Updated license

Revision 1.1 Revision 1.2 Revision 1.3

Date: 9/15/12Name: ChoLine #’s: 9Comment: Fixed M1()

SVN blame

Date: 9/1/12Name: AbeLine #’s: 4Comment: Changed M1(), see bug ID#42233

Page 31: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Appendix Accuracy of MK and SK Techniques

Precision

Recall

Automated techniques Vs. Manual inspection

ⓒ KAIST SE LAB 2013

Manual Count Source # Prec. Recall

APIRefactoringRevision

14 [MK] API-level refactoring detection 14 0.93 0.93

Inspection of change logs only 2 0.50 0.07

Inspection of bug reports only 5 0.75 0.21

FixRevision

62 [SK] Fix-revision detection 49 0.96 0.76

Inspection of change logs only 55 0.92 0.81

Inspection of bug reports only 49 0.94 0.74

• Percentage of actual fix revisions which are identified by the tool

• Percentage of identified fix revisions which are actual fix revisions

Page 32: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Appendix

Q1 result: Latent bugs A bug which is not fixed and is already uncovered in

earlier versions and is still present. Bugs that remain dormant are latent bugs. These bugs

are not found until one or more releases of the product.

32/27ⓒ KAIST SE LAB 2013

Page 33: An Empirical Investigation into the Role of API-Level …se.kaist.ac.kr/wp-content/uploads/2013/09/An-Empirical... · An Empirical Investigation into the Role of API-Level Refactorings

Appendix Q3: Do API-level refactorings facilitate bug fixes?

Q3.1: How many refactorings are done as part of bug fix?• Identify revisions including both refactoring and bug fix

ⓒ KAIST SE LAB 2013

Probability of fixes and refactorings at revision level

Subject P(F) P(R) P(R|F) P(R|not F) P(F|R) P(F|not R)

Eclipse JDT 25.0% 7.3% 12.0% 5.7% 41.5% 23.7%

JEdit 9.7% 3.8% 11.5% 3.0% 29.1% 8.9%

Columba 35.7% 8.6% 10.7% 7.4% 44.4% 34.8%

Fixes and refactorings often appear in the same revision.

Probability of fixes and refactorings at method level

Subject P(F) P(R) P(R|F) P(R|not F) P(F|R) P(F|not R)

Eclipse JDT 54.9% 28.6% 32.7% 23.6% 62.8% 51.7%

JEdit 41.4% 39.5% 31.5% 45.1% 33.0% 46.9%

Columba 34.0% 19.4% 13.8% 22.2% 24.3% 36.3%