| Summary: | [move method] incorrect update of destination to 'this' when moved via fields | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Jongwook Kim <jongwook.kim> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jongwook.kim, noopur_gupta |
| Version: | 3.8.1 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
This should be handled while fixing bug 444032. *** This bug has been marked as a duplicate of bug 444032 *** |
When A.m() is moved to class B via A.b below, Reference b is updated to 'this' after refactoring. That changes semantics. -------------------- Before (Output: 2) public class A { B b = new B(1); void n(B b1) { b = b1; } void m() { n(new B(2)); B b2 = b; // look how b changes after refactoring System.out.println(b2.i); } } public class B { int i = 0; public B(int j) { i = j; } } public class C { public static void main(String[] args) { A a = new A(); a.m(); } } -------------------- After (Output: 1) public class A { B b = new B(1); void n(B b1) { b = b1; } } public class B { int i = 0; public B(int j) { i = j; } void m(A a) { a.n(new B(2)); B b2 = this; // should be 'a.b', NOT 'this' System.out.println(b2.i); } } public class C { public static void main(String[] args) { A a = new A(); a.b.m(a); } }