| Summary: | [move method] method invocation introduces class-instance-creation as the parameter incorrectly | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Jongwook Kim <jongwook.kim> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jongwook.kim, manju656 |
| Version: | 4.2.2 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | stalebug | ||
The side effect occurs by creating two instances of class A. *** This bug has been marked as a duplicate of bug 313918 *** This is NOT a duplicate of bug 313918. The following example prints 2 before moving A.m() to b but 3 after the same refactoring: class A { static int i = 1; B b = B.singleton; A() { A.i++; } A m(){ return this; } } class B { static B singleton = new B(); } class C { static void main(String args[]) { new A().m(); System.out.println(A.i); } } The code snippet provided in the initial bug report had the same problem reported in bug 313918, comment 3. OK. The key point is that method invocation new A().m() is updated to new A().b.m(new A()) which has two different instances of class A. In general, class-instance-creation can exist inside a method body. From the example above, suppose another method foo returns new A() and the method invocation looks like foo().m(). The following has the same side effect: foo().m(foo()); //After Refactoring This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
When A.m() is moved to B via A.b, method invocation new A().m() is updated to new A().b.m(new A()). That is wrong (due to side effect). class A { B b; A m() { return this; } } class B { } class C { void n() { new A().m(); } }