Bug 79390

Summary: [1.5][compiler] ClassCastException creating a generic local class
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olivier Thomann CLA 2004-11-24 10:15:10 EST
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)
Comment 1 Philipe Mulet CLA 2004-11-25 03:10:18 EST
Problem lies in inneremulation, which did not step back to super type erasure as
it should.
Added regression test: GenericTypeTest#test428
Fixed
Comment 2 Olivier Thomann CLA 2004-12-14 17:49:51 EST
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)