Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 420726

Summary: [refactoring][move method] Code is broken when moving a method that is assigning to the parameter that is also the move destination.
Product: [Eclipse Project] JDT Reporter: Erlend Kristiansen <erlend.k>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jongwook.kim, markus.kell.r, stolz+bugzilla
Version: 4.3.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Erlend Kristiansen CLA 2013-10-30 10:15:35 EDT
Build id: 20130919-0819

Steps to reproduce:

1. Make the classes A and B:

public class A {
	void methodToMove(B b) {
		b = new B();
	}
}

public class B {
}


2. Perform Move Method refactoring on 'methodToMove' from A to B, with the following result:

public class A {
}

public class B {
	void methodToMove() {
		this = new B(); // <-- bug!
	}
}


Bug:

The method 'methodToMove' is now assigning to the 'this' keyword, which is not allowed in Java.
Comment 1 Markus Keller CLA 2013-10-30 10:49:34 EDT
Yes, we already detect the same problem when trying to move to a field that is assigned:

public class A {
	B b;
	void methodToMove() {
		b = new B();
	}
}

We should have the same test for parameters as well.

The error message could also use some love:
> In addition the target must be writable.

Should be something like:
In addition, replacing the target with 'this' must be legal.
Comment 2 Noopur Gupta CLA 2015-10-05 03:01:35 EDT
*** Bug 424654 has been marked as a duplicate of this bug. ***
Comment 3 Eclipse Genie CLA 2019-11-27 06:39:08 EST
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.