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

Bug 290430

Summary: [pull up] The Pull Up Method Refactoring can change the program behaviour by means of overriding [refactoring]
Product: [Eclipse Project] JDT Reporter: Johannes Gebauer <jogeb>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: akiezun, jongwook.kim, markus.kell.r, nikolaymetchev
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Johannes Gebauer CLA 2009-09-24 11:39:36 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Build Identifier: I20090611-1540

If a Pull Up Method Refactoring moves a method into a superclass that has other subclasses referenceing a related method that was declared in a superclass of the destination type, they reference the pulled up method after the refactoring. This problem can be caused by simple method calls that reference the method in a superclass or overriding methods using a super call.

The refactoring processor does not analyze the influence of overriding in other sublcasses. I think it should at least warn of changes in the behaviour.

Reproducible: Always

Steps to Reproduce:
1. 
Create the following classes:

public class SuperDestination {
	public void m() {
		System.out.println("super destination behaviour");
	}
}

public class Destination extends SuperDestination {
}

public class Referencer extends Destination {
	public void n() {
		m();
	}
}

public class SuperReferencer extends Destination {
	public void m() {
		super.m();
	}
}

public class DeclaringType extends Destination {
	public void m() {
		System.out.println("declaring type behaviour");
	}
}

2.
Now perform a pull up refactoring to move the method "DeclaringType.m()" to the class "Destination".

3.
The refactoring performs without giving a warning/error. This is not desirable because the behaviour of the refactored program changed in two points:

(a)
Before the refactoring the method body of "Referencer.n()" referenced the method "SuperDestination.m()".
After the refactoring it references the pulled up method "DeclaringType.m()" that causes a changed behaviour.

(b)
Before the refactoring the method body of "SuperReferencer.n()" referenced the method "SuperDestination.m()".
After the refactoring it references the pulled up method "DeclaringType.m()" that causes a changed behaviour.
Comment 1 Markus Keller CLA 2009-10-06 06:54:40 EDT
*** Bug 29522 has been marked as a duplicate of this bug. ***
Comment 2 Eclipse Genie CLA 2020-03-10 16:18:17 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.