Bug 194034 - [1.5][Compiler] Inconsistency with javac: subclass does not properly inherit generic method
Summary: [1.5][Compiler] Inconsistency with javac: subclass does not properly inherit ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 3.3.1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-22 15:23 EDT by Alex Kinneer CLA
Modified: 2007-09-28 06:28 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Kinneer CLA 2007-06-22 15:23:12 EDT
The following is a (somewhat silly) example that replicates the distilled behavior of production code that reveals the bug. It compiles in javac (with expected warnings), but Eclipse/compiler reports an error in the PurebredCatShopImpl class:

"The return type is incompatible with with CatShop.getPets(), CatShopImpl.getPets()"

I believe javac is correct here, as the method in question (getPets) should be inherited from the superclass. (The error message seems particularly bizarre: how can a method that doesn't even exist be type incompatible with anything?)

---- Test case ----

[Pet.java]
public interface Pet {
    void groom();
}

[PetShop.java]
import java.util.List;

public interface PetShop {
    List<Pet> getPets();
}

[Cat.java]
public interface Cat extends Pet {
    void giveFish();
}

[CatShop.java]
import java.util.List;

interface CatShop extends PetShop {
    <V extends Pet> List<? extends Cat> getPets();
}

[CatShopImpl.java]
import java.util.List;

public class CatShopImpl implements CatShop {
    public List<Pet> getPets() {
        return null;
    }
}

[PurebredCatShop.java]
public interface PurebredCatShop extends CatShop {

}

[PurebredCatShopImpl.java]
public class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {
    // Eclipse error in this (empty) class, on the class declaration line above
}


---- Configuration ----
Eclipse SDK
Version: 3.2.2
Build id: M20070212-1330

java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_08-b03, mixed mode)

Linux cse-swe-wk-01 2.6.17-gentoo-r8 #8 SMP Thu Oct 12 12:34:45 CDT 2006 x86_64 AMD Opteron(tm) Processor 252 AuthenticAMD GNU/Linux
Comment 1 Olivier Thomann CLA 2007-06-25 13:47:05 EDT
Reproduced with 3.3RC4.
javac 1.5.0_12 reports:
CatShopImpl.java:4: warning: getPets() in CatShopImpl implements <V>getPets() in CatShop; return type requires unchecked conversion
found   : java.util.List<Pet>
required: java.util.List<? extends Cat>
    public List<Pet> getPets() {
                     ^
PurebredCatShopImpl.java:1: warning: getPets() in CatShopImpl implements <V>getPets() in CatShop; return type requires unchecked conversion
found   : java.util.List<Pet>
required: java.util.List<? extends Cat>
public class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {
       ^
PurebredCatShopImpl.java:1: warning: getPets() in CatShopImpl implements <V>getPets() in CatShop; return type requires unchecked conversion
found   : java.util.List<Pet>
required: java.util.List<? extends Cat>
public class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {
       ^
3 warnings

We report:
----------
1. WARNING in D:\tests_sources\194034\CatShopImpl.java (at line 4)
	public List<Pet> getPets() {
	       ^^^^
Type safety: The return type List<Pet> for getPets() from the type CatShopImpl needs unchecked conversion to conform to List<? extends Cat> from the type CatShop
----------
----------
2. ERROR in D:\tests_sources\194034\PurebredCatShopImpl.java (at line 1)
	public class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {
	             ^^^^^^^^^^^^^^^^^^^
The return type is incompatible with CatShop.getPets(), CatShopImpl.getPets()
----------
2 problems (1 error, 1 warning)
Comment 2 Kent Johnson CLA 2007-06-25 15:21:06 EDT
Our error is reported against the class that implements the interface method while being compatible with the inherited superclass method... just as javac reports a warnining against the same class.

It appears we need to need to handle this case a type conversion warning instead of a type incompatibility error.
Comment 3 Kent Johnson CLA 2007-06-26 15:36:43 EDT
Added MethodVerifyTest test144 and corrected error messages in test077a
Comment 4 Philipe Mulet CLA 2007-06-27 07:49:58 EDT
Smells like a 3.3.1 fix as well. Pls make sure to keep patches for your fixes.
Comment 5 Kent Johnson CLA 2007-07-16 15:22:33 EDT
Released for 3.3.1
Comment 6 Frederic Fusier CLA 2007-08-03 11:28:23 EDT
Verified for 3.4M1 using build I20070802-0800.
Comment 7 Philipe Mulet CLA 2007-08-29 06:27:13 EDT
+1 for 3.3.1
Comment 8 Maxime Daniel CLA 2007-09-03 07:47:03 EDT
Verified for 3.3.1 using build M20070831-2000.