|
Duplicate :
|
|
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Relates :
|
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux nacar 2.6.18-suspend2-r1 #3 PREEMPT Tue Dec 26 21:51:39 COT 2006 i686 Intel(R) Pentium(R) M processor 2.00GHz GenuineIntel GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Having an annotation that contain an element whose value is of type Class[], attempting to read this value results in a MirroredTypeException and not a MirroredTypesException as specified ( http://java.sun.com/javase/6/docs/api/javax/lang/model/element/Element.html#getAnnotation(java.lang.Class) )
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create file AnnotationBug.java
---
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
@interface A {
Class[] value() default {String.class, Number.class};
}
@SupportedAnnotationTypes({"A"})
@A
public class AnnotationBug extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
Set<? extends Element> elements = roundEnv.getRootElements();
for (Element e : elements) {
A a;
if ((a= e.getAnnotation(A.class)) != null) {
System.err.println(a.value());
}
}
}
return true;
}
}
---
2. Run:
---
javac -processor AnnotationBug AnnotationBug.java
---
...
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
javax.lang.model.type.MirroredTypeException: Attempt to access Class object for TypeMirror java.lang.String
...
---
3. :(
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
---
...
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
javax.lang.model.type.MirroredTypesException:...
...
---
:)
ACTUAL -
---
...
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
javax.lang.model.type.MirroredTypeException: Attempt to access Class object for TypeMirror java.lang.String
...
---
:(
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
@interface A {
Class[] value() default {String.class, Number.class};
}
@SupportedAnnotationTypes({"A"})
@A
public class AnnotationBug extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
Set<? extends Element> elements = roundEnv.getRootElements();
for (Element e : elements) {
A a;
if ((a= e.getAnnotation(A.class)) != null) {
System.err.println(a.value());
}
}
}
return true;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use Class[] annotation members ever ever.
:(
|