Community
Participate
Working Groups
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
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)
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.
Added MethodVerifyTest test144 and corrected error messages in test077a
Smells like a 3.3.1 fix as well. Pls make sure to keep patches for your fixes.
Released for 3.3.1
Verified for 3.4M1 using build I20070802-0800.
+1 for 3.3.1
Verified for 3.3.1 using build M20070831-2000.