Name: siR10004 Date: 04/29/2004
List of annotations of the class 'Documented', returned by 'getDeclaredAnnotations'
method, may be wrong in some cases.
To reproduce, compile the following program:
----------------------------------------------------------------
import java.lang.annotation.*;
public class V {
public static void main (String[] args) throws Throwable {
for (int i = 0; i < args.length; i++)
probe(args[i]);
}
static void probe (String fqn) throws Throwable {
System.out.println("CLASS " + fqn);
Class c = Class.forName(fqn, false, null);
Annotation[] alist = c.getDeclaredAnnotations();
if (alist != null)
for (int i = 0; i < alist.length; i++) {
Class a = alist[i].annotationType();
System.out.println(" Annotation " + a.getName());
}
}
}
----------------------------------------------------------------
Please note the difference in the annotations lists presented on
the class 'Documented' when this sample program is run in a two
slightly different ways:
----------------------------------------------------------------
% java -cp classes V java.lang.annotation.Documented
CLASS java.lang.annotation.Documented
Annotation java.lang.annotation.Documented
Annotation java.lang.annotation.Retention
Annotation java.lang.annotation.Target
% java -cp classes V java.lang.Deprecated java.lang.annotation.Documented
CLASS java.lang.Deprecated
Annotation java.lang.annotation.Documented
Annotation java.lang.annotation.Retention
CLASS java.lang.annotation.Documented
Annotation java.lang.annotation.Retention
Annotation java.lang.annotation.Target
----------------------------------------------------------------
In the second run, the list of annotations is missing
one item - the 'Documented' annotation itself.
This bug is reproduced on the build b49.
======================================================================
- duplicates
-
JDK-5037685 (ann) Class.getAnnotation return null but the annotation is present
- Resolved