Bug 289306 - [use supertype] incorrectly changes method return type to return type of overridden method
Summary: [use supertype] incorrectly changes method return type to return type of over...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2009-09-13 20:55 EDT by Vilas Jagannath CLA
Modified: 2019-10-16 19:57 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vilas Jagannath CLA 2009-09-13 20:55:01 EDT
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.
Comment 1 Vilas Jagannath CLA 2009-09-13 21:05:16 EDT
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()"
Comment 2 Markus Keller CLA 2009-09-14 13:21:56 EDT
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(..)).
Comment 3 Markus Keller CLA 2009-09-14 13:31:29 EDT
> 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.
Comment 4 Eclipse Genie CLA 2019-10-16 19:57:12 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.

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.