Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Making Software Refactorings Safer
Anna Maria Eilertsen
@Sowhow
Supervised by: Anya Bagge1
Volker Stolz 2
1Inst. for Infor...
Software Refactorings
“Behaviour preserving program
transformation”
Anna Maria Eilertsen @sowhow (Inst. for Informatikk, U...
Software Refactoring Tools
Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Mak...
Unsafe Refactorings
“The primary risk is regression, mostly from
misunderstanding subtle corner cases in the
original code...
Unsafe Refactoring Example
Extract Local Variable
In Java/Eclipse:
Before
1 public void f() {
2 x.n();
3 setX();
4 x.n();
...
An analysing problem
x = new X();
setX(); // x = new X();
1 public void f() {
2 X temp = x;
3 temp.n();
4 setX();
5 temp.n...
Extract Local Variable
Simplified example:
1 public class C {
2 public X x = new X();
3 {//initializer
4 x.myC = this;
5 }
...
Extract Local Variable
Refactored:
1 public class C {
2 public X x = new X();
3 {//initializer
4 x.myC = this;
5 }
6
7 pub...
Extract Local Variable
With dynamic checks:
1 public class C {
2 public X x = new X();
3 {//initializer
4 x.myC = this;
5 ...
Extract And Move Method
A similar problem:
1 public class C {
2 public X x = new X();
3 {//initializer
4 x.myC = this;
5 }...
Experiment: Case study
Case: Eclipse JDT UI source code
Experiment:
Execute our modified refactorings on Eclipse JDT UI pro...
Experiment: Results
Extract Local Extract and
Variable Move Method
Executed refactorings 4538 755
Total number of asserts ...
Discussion
Take-away and questions:
Extract Local Extract and
Variable Move Method
Executed refactorings 4538 755
Total nu...
Experiment: Development
Eclipse refactoring plug-in
Modify Eclipse’s refactorings to introduce asserts
Extract Local Varia...
Upcoming SlideShare
Loading in …5
×

Making Software Refactorings Safer

621 views

Published on

How dynamic precondition checking can increase the correctness of the Extract Local Variable and Extract And Move Method refactorings. Masterpresentation from the SATToSE conference.

Published in: Data & Analytics
  • Be the first to comment

  • Be the first to like this

Making Software Refactorings Safer

  1. 1. Making Software Refactorings Safer Anna Maria Eilertsen @Sowhow Supervised by: Anya Bagge1 Volker Stolz 2 1Inst. for Informatikk, Universitetet i Bergen 2Inst. for Data- og Realfag, Høgskolen i Bergen Norway July 12, 2016 The results of this thesis has been accepted to the ISOLA1 conference as a paper. 1 http://www.isola-conference.org/isola2016/ Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 1 / 14
  2. 2. Software Refactorings “Behaviour preserving program transformation” Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 2 / 14
  3. 3. Software Refactoring Tools Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 3 / 14
  4. 4. Unsafe Refactorings “The primary risk is regression, mostly from misunderstanding subtle corner cases in the original code and not accounting for them in the refactored code.” – interviewee, Microsoft developer, Kim et al., 2012 Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 4 / 14
  5. 5. Unsafe Refactoring Example Extract Local Variable In Java/Eclipse: Before 1 public void f() { 2 x.n(); 3 setX(); 4 x.n(); 5 } After 1 public void f() { 2 X temp = x; 3 temp.n(); 4 setX(); 5 temp.n(); 6 } Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 5 / 14
  6. 6. An analysing problem x = new X(); setX(); // x = new X(); 1 public void f() { 2 X temp = x; 3 temp.n(); 4 setX(); 5 temp.n(); 6 } Solution: assert temp == x; ∗ Dog art from Hyperbole and a Half Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 6 / 14
  7. 7. Extract Local Variable Simplified example: 1 public class C { 2 public X x = new X(); 3 {//initializer 4 x.myC = this; 5 } 6 7 public void f(){ 8 x.n(); 9 x.m(); 0 x.n(); 1 } 2 } 1 public class X{ 2 public C myC; 3 4 public void m(){ 5 myC.x = new X(); 6 } 7 8 public void n(){ 9 System.out.println( 10 this.hashCode()); 11 } 12 } Output: 1735600054 21685669 skip example Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 7 / 14
  8. 8. Extract Local Variable Refactored: 1 public class C { 2 public X x = new X(); 3 {//initializer 4 x.myC = this; 5 } 6 7 public void f(){ 8 X temp = x; 9 temp.n(); 0 temp.m(); 1 temp.n(); 2 } 3 } 1 public class X{ 2 public C myC; 3 4 public void m(){ 5 myC.x = new X(); 6 } 7 8 public void n(){ 9 System.out.println( 10 this.hashCode()); 11 } 12 } Output: 1735600054 1735600054 Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 8 / 14
  9. 9. Extract Local Variable With dynamic checks: 1 public class C { 2 public X x = new X(); 3 {//initializer 4 x.myC = this; 5 } 6 public void f(){ 7 X temp = x; 8 assert temp == x; 9 temp.n(); 0 assert temp == x; 1 temp.m(); 2 assert temp == x; 3 temp.n(); 1 public class X{ 2 public C myC; 3 4 public void m(){ 5 myC.x = new X(); 6 } 7 8 public void n(){ 9 System.out.println( 10 this.hashCode()); 11 } 12 } Output: 1735600054 Exception in thread ”main” java.lang.AssertionError Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 9 / 14
  10. 10. Extract And Move Method A similar problem: 1 public class C { 2 public X x = new X(); 3 {//initializer 4 x.myC = this; 5 } 6 public void f(){ 7 x.bar(this); 8 } 9 } 1 public class X{ 2 ... 3 void bar(C c){ 4 this.n(); 5 assert this == c.x; 6 this.m(); 7 assert this == c.x; 8 this.n(); 9 } 10 } Similar how? Evaluate x once. Refer to that value by this Substitute every occurrence of x with this Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 10 / 14
  11. 11. Experiment: Case study Case: Eclipse JDT UI source code Experiment: Execute our modified refactorings on Eclipse JDT UI project Run Eclipse test suite Look for triggered asserts Profit!! Need custom automated refactoring tool. Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 11 / 14
  12. 12. Experiment: Results Extract Local Extract and Variable Move Method Executed refactorings 4538 755 Total number of asserts 7665 610 Resulting compile errors 0 14 Successful Tests 2392 2151 Unsuccessful Tests 4 245 Asserts triggered 2 / 136∗ 0 ∗ 136 instances of the same 2 assert statements Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 12 / 14
  13. 13. Discussion Take-away and questions: Extract Local Extract and Variable Move Method Executed refactorings 4538 755 Total number of asserts 7665 610 Resulting compile errors 0 14 Successful Tests 2392 2151 Unsuccessful Tests 4 245 Asserts triggered 2 / 136 0 Dynamic preconditions can be useful! Assert statements are incomplete. Show or hide the asserts from the programmer? Is reference equivalence too strict? Thank you! ∗ Art with face is from Hyperbole and a Half Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 13 / 14
  14. 14. Experiment: Development Eclipse refactoring plug-in Modify Eclipse’s refactorings to introduce asserts Extract Local Variable Extract And Move Method Automate refactoring process Execute on Java project One refactoring per method Custom heuristic for finding refactoring targets Anna Maria Eilertsen @sowhow (Inst. for Informatikk, Universitetet i Bergen, Inst. for Data-Making Software Refactorings Safer July 12, 2016 14 / 14

×