Bug 82504 - [compiler][1.5] ClassCastException when parsing a CastExpression between an array type and a type variable
Summary: [compiler][1.5] ClassCastException when parsing a CastExpression between an a...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-10 15:28 EST by Markus Keller CLA
Modified: 2005-02-15 05:40 EST (History)
0 users

See Also:


Attachments
Apply on Expression class in HEAD (1004 bytes, patch)
2005-01-10 15:59 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2005-01-10 15:28:49 EST
I20050104-1600 + jdt.core v_530a

class F<T> {
	Object[] objectArr;
	void foo() {
		T x= (T) objectArr;
	}
}

Error 2005-01-10 21:22:57.662 An internal error occurred during: "Java AST
creation".
java.lang.ClassCastException
at
org.eclipse.jdt.internal.compiler.ast.Expression.checkCastTypesCompatibility(Expression.java:300)
at
org.eclipse.jdt.internal.compiler.ast.CastExpression.resolveType(CastExpression.java:376)
at
org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:201)
at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:411)
at
org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:160)
at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:389)
at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1014)
at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1063)
at
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:280)
at
org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:651)
at
org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:443)
at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:708)
at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:574)
at
org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:563)
at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:494)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:165)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:142)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)
Comment 1 Olivier Thomann CLA 2005-01-10 15:59:36 EST
Created attachment 17058 [details]
Apply on Expression class in HEAD
Comment 2 Markus Keller CLA 2005-01-10 16:23:32 EST
Cool, that patch does the job. But in the meantime, I found that the other
direction suffers from the same / a similar problem

class F<T> {
	void foo(T o) {
		int[] x= (int[]) o;
	}
}

Stacktrace with patch applied:

java.lang.ClassCastException
	at
org.eclipse.jdt.internal.compiler.ast.Expression.checkCastTypesCompatibility(Expression.java:331)
	at
org.eclipse.jdt.internal.compiler.ast.CastExpression.resolveType(CastExpression.java:376)
	at
org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:201)
...
Comment 3 Philipe Mulet CLA 2005-01-11 04:07:39 EST
Olivier - I don't think the patch works. Using the leaf type doesn't provide the
right semantics. I have another version in progress, but must still adjust
warnings (unsafe cast, unnecessary cast).
Comment 4 Philipe Mulet CLA 2005-01-11 07:39:52 EST
New behavior implemented. Added regression test: GenericTypeTest#test454.
Fixed (will released post today's 2pm integration since too late).
Comment 5 Jerome Lanneluc CLA 2005-02-15 05:40:26 EST
Verified in I20050214