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

Bug 444032

Summary: [move method] incorrect update of referencing the member of destination when moved via fields
Product: [Eclipse Project] JDT Reporter: Jongwook Kim <jongwook.kim>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jongwook.kim, stolz+bugzilla
Version: 3.8.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Jongwook Kim CLA 2014-09-13 18:09:32 EDT
When A.m() is moved to class B via A.b below,
Reference b.i is updated to i 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));
		System.out.println(b.i);  // what should b.i be after move?
	}
}

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));
		System.out.println(i);      // should be a.b.i, NOT i
	}
}

public class C {
	public static void main(String[] args) {
		A a = new A();
		a.b.m(a);
	}
}
Comment 1 Noopur Gupta CLA 2014-09-17 04:38:49 EDT
Reproducible in Eclipse 3.8.1 also.
Comment 2 Noopur Gupta CLA 2014-09-17 04:43:54 EDT
*** Bug 444284 has been marked as a duplicate of this bug. ***
Comment 3 Volker Stolz CLA 2015-10-02 05:23:37 EDT
Note to developers:
Note that this will not be easy to fix as there cannot be a complete static check for this property.

http://boemund.dagstuhl.de/mat/Files/14/14211/14211.StolzVolker.Slides.pdf
http://prezi.com/w5dikhkpjzmu/?utm_campaign=share&utm_medium=copy&rc=ex0share
Comment 4 Volker Stolz CLA 2015-10-02 05:27:02 EDT
(In reply to Volker Stolz from comment #3)
> Note to developers:
> Note that this will not be easy to fix as there cannot be a complete static
> check for this property.
> 
> http://boemund.dagstuhl.de/mat/Files/14/14211/14211.StolzVolker.Slides.pdf
> http://prezi.com/w5dikhkpjzmu/?utm_campaign=share&utm_medium=copy&rc=ex0share

I clicked a bit too fast. Of course this can be easily fixed to follow Jongwook's suggestion. Figuring out when using the "shorter" form (as will be probably intended by a user) is correct is difficult.
Comment 5 Eclipse Genie CLA 2020-04-27 12:55:16 EDT
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.