Community
Participate
Working Groups
Using latest, the following code leads to a ClassCastException. public class X { public static void foo() { class A<T extends Number> { T t = null; T get() { return t; } } A<Long> a = new A<Long>() { Long get() { return new Long(5); } }; } } ---------- 1. ERROR in C:\tests_sources\X.java (at line 0) public class X { ^ Internal compiler error java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.manageEnclosingInstanceAccessIfNecessary(TypeDeclaration.java:740) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:204) at org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression.analyseCode(QualifiedAllocationExpression.java:66) at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.analyseCode(LocalDeclaration.java:48) at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:76) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:707) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:264) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:80) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:513) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:335) at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:1681) at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:375) at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:268) at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:260) at org.eclipse.jdt.core.tools.compiler.Compile.main(Compile.java:19)
Problem lies in inneremulation, which did not step back to super type erasure as it should. Added regression test: GenericTypeTest#test428 Fixed
Verified in 200412140800 that the CCE doesn't occur anymore, but we report a warning. ---------- 1. WARNING in C:\tests_sources\X.java (at line 11) Long get() { ^^^^ Type safety: The return type Long of the method get() of type new A<Long>(){} needs unchecked conversion to conform to the return type T of inherited method ---------- 1 problem (1 warning)