JDK-8010679 : Clarify "present" and annotation ordering in Core Reflection for Annotations
  • Type: Task
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-03-22
  • Updated: 2018-11-07
  • Resolved: 2013-07-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b100Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
No implementation changes are needed. Only the javadoc needs to be clarified:

1)  In AnnotatedElement, the interface-level javadoc should have these definitions:

- An annotation A is directly present on an element E if E has a RuntimeVisibleAnnotations or RuntimeVisibleParameterAnnotations or RuntimeVisibleTypeAnnotations attribute, and the attribute contains A.

- An annotation A is indirectly present on an element E if E has a RuntimeVisibleAnnotations or RuntimeVisibleParameterAnnotations or RuntimeVisibleTypeAnnotations attribute, and A's type is repeatable, and the attribute contains exactly one annotation whose value element contains A and whose type is the containing annotation type of A's type (��9.6).

- An annotation A is present on an element E if either:
  - A is directly present on E; or
  - No annotation of A's type is directly present on E, and E is a class, and A's type is inheritable (��9.6.3.3), and A is present on the superclass of E.

- An annotation A is associated with an element E if either:
  - A is directly or indirectly present on E; or
  - No annotation of A's type is directly or indirectly present on E, and E is a class, and A's type is inheritable (��9.6.3.3), and A is associated with the superclass of E.

2) In AnnotatedElement#getDeclaredAnnotationsByType, the javadoc should be:

Returns the annotations which are directly or indirectly present on this element. The order of annotations which are directly or indirectly present on an element E is computed as if indirectly present annotations on E are directly present on E in place of their container annotation, in the order in which they appear in the value element of the container annotation.

@return: all this element's annotations for the specified annotation type if directly or indirectly present on this element, else an array of length zero.

3) In AnnotatedElement#getAnnotationsByType, the javadoc should be:

Returns the annotations which are associated with this element. The order of annotations which are directly or indirectly present on an element E is computed as if indirectly present annotations on E are directly present on E in place of their container annotation, in the order in which they appear in the value element of the container annotation.

@return: all this element's annotations for the specified annotation type if associated with this element, else an array of length zero.

4) In AnnotatedElement#getDeclaredAnnotation, the word "directly" is missing:

Returns this element's annotation for the specified type if such an annotation is directly present.

@return: this element's annotation for the specified annotation type if directly present on this element, else null.
Comments
See review thread: http://mail.openjdk.java.net/pipermail/enhanced-metadata-spec-discuss/2013-July/000216.html
12-07-2013

I have question/suggestion about this javadoc. In j.l.r.AccessibleObject, j.l.r.Executable, j.l.Package, j.l.r.Method, j.l.r.Field, j.l.r.Constructor, j.l.r.Parameter there are also implementations and javadocs for the methods getDeclaredAnnotation(Class), getDeclaredAnnotations() and getDeclaredAnnotationsByType(Class). But behavior of those methods are the same as getAnnotation(Class), getAnnotations() and getAnnotationsByType(Class) corresponding. I think javadocs for these methods could be changed for these classes, because now javadocs contain words about inherited annotations (like "This method ignores inherited annotations." for j.l.r.Executable.getDeclaredAnnotations()). Or maybe these methods could be moved to j.l.Class... WDYT about it?
10-07-2013