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

Bug 233437

Summary: [generalize type] fails to see lack of overriding [Refactoring]
Product: [Eclipse Project] JDT Reporter: Friedrich Steimann <steimann>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, developer, martinae
Version: 3.3.1Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Friedrich Steimann CLA 2008-05-22 08:31:59 EDT
Build ID: M20071023-1652

Steps To Reproduce:

package a;
public class A {
	void m() {}
}

package b;
import a.A;
public class B extends A {
	void m() {} // does not override!
}

package b;
public class C {
	B b;
	void m() {
		b.m();
	}
}

Generalzing declared type of b to A causes an access violation. A should be excluded from list of possible supertypes.

More information:
Comment 1 Friedrich Steimann CLA 2008-05-23 01:07:37 EDT
The problem is even worse when C is in a:

package a;
public class A {
	void m() {} // not public
}
package a;
import b.B;
public class C {
	B b;
	void m() {
		b.m();
	}
}

package b;
import a.A;
public class B extends A {
	public void m() {}
}

Generalizing b changes program behaviour.
Comment 2 Friedrich Steimann CLA 2008-05-23 05:12:36 EDT
yet another example (all classes in one package):

public class A {
	private void m() {} // private!
}

public class B extends A {
	public void m() {} // not overridden
}

public class C {
	B b;
	void m() {
		b.m();
	}
}

Should not allow B b to be generalized to A b!
Comment 3 Friedrich Steimann CLA 2008-05-23 05:35:16 EDT
and one more, again changing behaviour both in one package):

class A {
  B b; 
  private void m() {
    b.m();
  }
}

class B extends A {
  void m() {}
}
Comment 4 Martin Aeschlimann CLA 2008-05-23 06:27:46 EDT
Help would be welcome...
Comment 5 Jens Von Pilgrim CLA 2010-06-09 13:47:17 EDT
In all three examples, "Use supetype where possible"  creates the same (wrong) results.
Comment 6 Eclipse Genie CLA 2020-02-13 08:03:02 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. 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.