Bug 167217 - [1.5][compiler] ClassCastException during annotation code generation
Summary: [1.5][compiler] ClassCastException during annotation code generation
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-08 04:57 EST by David Audel CLA
Modified: 2007-01-16 06:10 EST (History)
1 user (show)

See Also:


Attachments
Proposed fix (1.71 KB, patch)
2006-12-08 11:24 EST, Olivier Thomann CLA
no flags Details | Diff
Regression tests (8.46 KB, patch)
2006-12-08 11:30 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 David Audel CLA 2006-12-08 04:57:18 EST
build I20061205-1200

//zz\MyA1.java
package zz;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Target;
@Target({TYPE})
public @interface MyA1 {
}

//zz\MyA2.java
package zz;
public @interface MyA2 {
	public static final MyA1 XX = null;
}

//zz\MyB1.java
package zz;
public @interface MyB1 {
	MyA1 value();
}

//TestAnnot.java
import zz.*;
public class TestAnnot {
	@MyB1(MyA2.XX)
	public void foo(){}
}

When TestAnnot is reconciled the following exception occurs and is shown in the problem view.


va.lang.ClassCastException: org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference
	at org.eclipse.jdt.internal.compiler.ClassFile.generateElementValueForNonConstantExpression(ClassFile.java:5215)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateElementValue(ClassFile.java:5096)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateAnnotation(ClassFile.java:5048)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateRuntimeAnnotations(ClassFile.java:5567)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateMethodInfoAttribute(ClassFile.java:5403)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateMethodInfoAttribute(ClassFile.java:5254)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:210)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:176)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:530)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:581)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:215)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:662)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:695)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:177)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:249)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:166)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:85)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:720)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:779)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1147)
Comment 1 Olivier Thomann CLA 2006-12-08 10:38:07 EST
This is a bug in the compiler.
We don't reject the annotation definition in TestAnnot.
javac 1.5.0 reports:
zz/TestAnnot.java:4: annotation value must be an annotation
        @MyB1(MyA2.XX)
                  ^
Comment 2 Olivier Thomann CLA 2006-12-08 11:24:42 EST
Created attachment 55318 [details]
Proposed fix
Comment 3 Olivier Thomann CLA 2006-12-08 11:30:54 EST
Created attachment 55320 [details]
Regression tests
Comment 4 Olivier Thomann CLA 2006-12-08 11:31:13 EST
Philippe, please double-check.
Comment 5 Philipe Mulet CLA 2006-12-08 11:44:21 EST
+1. Feels something we should address in 3.2.2 as well.
Comment 6 Olivier Thomann CLA 2006-12-08 14:02:35 EST
Released for 3.3M4.
Regression tests added.
org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test219/224
Comment 7 Olivier Thomann CLA 2006-12-08 14:04:12 EST
Reopen to backport to 3.2.2
Comment 8 Olivier Thomann CLA 2006-12-08 14:05:18 EST
Released for 3.2.2.
Same regression tests.
Comment 9 David Audel CLA 2006-12-12 11:27:34 EST
Verified for 3.3M4 with I20061212-0010.
Comment 10 Maxime Daniel CLA 2007-01-16 06:10:25 EST
Verified for 3.2.2 using build M20070112-1200.