JDK-6569057 : Generics regression on cast
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-06-13
  • Updated: 2011-02-16
  • Resolved: 2010-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
javac 1.6.0_01

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
javac 1.6 complains of incomparable types when trying to compile
Main.java but javac 1.5 does not. This sounds like a regression
since the types do seem comparable.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the attached code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No compilation error.
ACTUAL -
javac complains of incomparable types in Main.java

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Main.java:7: incomparable types: bugs.case02.Token<bugs.case02.Foo.Tag,bugs.case02.Foo> and bugs.case02.Token<capture#636 of ?,capture#203 of ? extends bugs.case02.Entity<capture#636 of ?>>
        boolean z1 = Token.FOO == x.getToken();
                               ^
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

package bugs;

public interface Entity<T extends Entity.Tag<?>> {

    public EntityToken<T, ? extends Entity<T>> getToken();

    public static interface Tag<E extends Entity<?>> { 

        public EntityToken<? extends Tag<E>, E> getToken();
    }
}

package bugs;

public class Glycan implements Entity<Glycan.Tag> {

    public EntityToken<Glycan.Tag, Glycan> getToken() { 
        return EntityToken.GLYCAN; 
    }

    public static class Tag implements Entity.Tag<Glycan> {

        public EntityToken<Glycan.Tag, Glycan> getToken() { 
            return EntityToken.GLYCAN; 
        }
    }   
}

package bugs;

public class EntityToken<T extends Entity.Tag<?>, E extends Entity<?>> {

    private EntityToken() { }

    public static final EntityToken<Glycan.Tag, Glycan> GLYCAN = 
        new EntityToken<Glycan.Tag, Glycan>();
}

package bugs;

public class Main2 {

    public static <E extends Entity<?>> E transform(E x) {
        return x.getToken() == EntityToken.GLYCAN ? x : null;
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
See the Main.java source.

Comments
EVALUATION Not reproducible in JDK 7 after the fix of 6932571.
23-08-2010