Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Alexey Kudravtsev 
Subsystem
Editor. Error Highlighting 
Affected versions
Fixed in
Fixed in build
Next build 
Build
7364
Fixed in build
7599
  • Submitted by   Matthias Ernst
    2 years ago (23 Nov 2007 23:25)
  • Updated by   root
    3 weeks ago (17 Jan 2010 19:55)
  • Jira: IDEA-42064
    (history, comments)

IDEA-42064

good code red: inheriting from raw type: "attempting to use incompatible return type"

0
package java.raw;

import java.util.Collections;
import java.util.List;

public class ExtendsRaw {
public static class Base<T> {
public List<T> elements() { return null; }
}

public static class Derived<T> extends Base<T> {}

public static class MostDerived extends Derived {
public List<MostDerived> elements() {
return Collections.emptyList();
}
}
}

MostDerived#elements is flagged red (incompatible return type) but compiles fine. I believe it's good according to the JLS.

Interestingly, if MostDerived inherits directly from Base, the error flag goes away.


Issue was resolved
Comments (2)
 
History (1)
 
Links
 
Eugene Vigdorchik
  Eugene Vigdorchik
25 Nov 2007 14:33
(2 years ago)
#permalink
What makes you believe javac is right and IDEA is wrong here?
Matthias Ernst
  Matthias Ernst
25 Nov 2007 15:26
(2 years ago)
#permalink
What makes you believe javac is right and IDEA is wrong here?


Three indications:
1. IDEA behaves differently for "MostDerived extends Derived extends Base" (red) and "MostDerived extends Base" (green). I can't think of an explanation for that other than there's a bug.
2. It also compiles fine when I switch to eclipse compiler.
3. From JLS 4.8 "Raw Types" I read that the inherited method "elements" from Base has the raw return type "List" that is overridden with "List<MostDerived>". According to 4.10.2, List<MostDerived> is a subtype of the raw type List, so the overriding is correct.