Community
Participate
Working Groups
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.14) Gecko/2009090216 Ubuntu/9.04 (jaunty) Firefox/3.0.14 Build Identifier: M20080221-1800 When the use super type where possible refactoring is applied to a program (shown in steps) with complex class hierarchy, it incorrectly changes the return type of a method in the program such that it does not compile any more. Reproducible: Always Steps to Reproduce: 1. Copy the following code into a java file named A.java: class A implements B { public A m() { A a = null; return a; } } interface B extends C { public B m(); } interface C { public C m(); } 2. Apply the use super type where possible refactoring on class A and choose interface C as type to use instead of A . 3. The refactoring incorrectly changes the return type of method A.m to type C. The program no longer compiles.
Here the non compilable program that results from applying the refactoring: class A implements B { public C m() { C a = null; return a; } } interface B extends C { public B m(); } interface C { public C m(); } The compilation error says "The return type of A.m() is incompatible with B.m()"
Looks like the refactoring does not properly deal with covariant return types. Bug is probably near SuperTypeConstraintsCreator.endVisit(MethodDeclaration), where overridden methods are only considered for parameter types but not for the return type (see call to getOriginalMethods(..)).
> Bug is probably near SuperTypeConstraintsCreator.endVisit(MethodDeclaration), > where overridden methods are only considered for parameter types but not for > the return type (see call to getOriginalMethods(..)). Hm, maybe not, see SuperTypeConstraintsCreator.endVisit(IMethodBinding). Could be related to bug 233796.
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.