|
Quick Lists
|
|
Bug ID:
|
6322301
|
|
Votes
|
0
|
|
Synopsis
|
unknown annotations are not ignored in Class.getAnnotations
|
|
Category
|
java:classes_lang
|
|
Reported Against
|
5.0
|
|
Release Fixed
|
5.0u6(b04),
mustang(b61) (Bug ID:2131479)
|
|
State
|
10-Fix Delivered,
Verified,
bug
|
|
Priority:
|
1-Very High
|
|
Related Bugs
|
6331821
,
5041778
|
|
Submit Date
|
10-SEP-2005
|
|
Description
|
If I use Class.getAnnotations to discover all the annotations on a class,
and the class includes annotations that are unknown to the runtime (e.g.,
because the class was annotated with vendor-specific annotations for one
app server and is being deployed on another app server), I get an exception
and can't discover any of the annotations on the class. According to the
JSR-175 spec lead, unknown annotations must be ignored by getAnnotations.
Posted Date : 2005-09-10 00:23:52.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
I've reproduced the reported symptoms with a simple test case. The stack trace for my test is
Exception in thread "main" java.lang.TypeNotPresentException: Type b.Bar not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:98)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:351)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:175)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3005)
at java.lang.Class.getAnnotations(Class.java:2987)
at Test.main(Test.java:10)
Caused by: java.lang.ClassNotFoundException: b.Bar
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
The proximal cause for this problem seems to be the method sun.reflect.annotation.AnnotationParser.parseAnnotation catching NoClassDefFoundError instead of TypeNotPresentException; the latter is thrown by the ParseSig. At the bottom of the stack, sun.reflect.generics.factory.CoreReflectionFactory does a Class.forName on the name of the annotation in question, catches any ClassNotFoundException and throws a TypeNotPresentException instead.
Adding a catch block at least gets the simple test case to pass; with this change the core reflection and annotation regression tests still pass too.
More analysis will be needed to verify this fix is sufficient and correct.
Posted Date : 2005-09-10 05:11:58.0
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |