-
Bug
-
Resolution: Fixed
-
P3
-
6, 6u10, 6u29, 7
-
b100
-
generic, x86
-
generic, linux, windows_7
-
Verified
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.
:(
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.
:(
- duplicates
-
JDK-6764597 MirroredTypesException never thrown
- Closed
-
JDK-6798955 Make MirroredTypesException be the parent class of MirroredTypeException
- Closed
-
JDK-6545679 Annotations with 'Class[] value()' get their values lost
- Closed
-
JDK-7129786 MirroredTypeException is thrown instead of MirroredTypesException
- Closed
- relates to
-
JDK-6583626 Improve serialization support in javax.lang.model.type exception classes
- Closed