-
Bug
-
Resolution: Unresolved
-
P4
-
13.0.2
A DESCRIPTION OF THE PROBLEM :
The Java Language Specification contradicts itself regarding annotations with targets FIELD and TYPE_USE.
JLS 9.7.4 (https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.7.4):
> @Foo is a declaration annotation on f if Foo is meta-annotated by @Target(ElementType.FIELD), and a type
> annotation on int if Foo is meta-annotated by @Target(ElementType.TYPE_USE). It is possible for @Foo to be
> both a declaration annotation and a type annotation simultaneously.
and
> If the annotation's type is applicable in the declaration context corresponding to the declaration and in type
> contexts, then the annotation is deemed to apply to both the declaration and the type which is closest to the
> annotation.
Both contradict:
>If TA is additionally meta-annotated with @Target(ElementType.FIELD), then the term @TA java.lang.Object is
> legal in locations which are both declaration and type contexts, such as a field declaration @TA
> java.lang.Object f;. Here, @TA is deemed to apply to the declaration of f (and not to the type java.lang.Object)
> because TA is applicable in the field declaration context.
The current behavior is the one from the first two quotes: The annotation is applied to the declaration (also applies to methods, parameters and constructors) AND to the type.
Related to this is JDK-8177557, for which the comment quotes the incorrect JLS section.
Other related issues:
-JDK-8006703: Confirms that the behavior in the two first quotes is intended
- JDK-8077585
- JDK-8223936: Which covers the case where the annotation is not admissible as TYPE_USE
-JDK-8145095: Confirms that the behavior in the two first quotes is intended
The Java Language Specification contradicts itself regarding annotations with targets FIELD and TYPE_USE.
JLS 9.7.4 (https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.7.4):
> @Foo is a declaration annotation on f if Foo is meta-annotated by @Target(ElementType.FIELD), and a type
> annotation on int if Foo is meta-annotated by @Target(ElementType.TYPE_USE). It is possible for @Foo to be
> both a declaration annotation and a type annotation simultaneously.
and
> If the annotation's type is applicable in the declaration context corresponding to the declaration and in type
> contexts, then the annotation is deemed to apply to both the declaration and the type which is closest to the
> annotation.
Both contradict:
>If TA is additionally meta-annotated with @Target(ElementType.FIELD), then the term @TA java.lang.Object is
> legal in locations which are both declaration and type contexts, such as a field declaration @TA
> java.lang.Object f;. Here, @TA is deemed to apply to the declaration of f (and not to the type java.lang.Object)
> because TA is applicable in the field declaration context.
The current behavior is the one from the first two quotes: The annotation is applied to the declaration (also applies to methods, parameters and constructors) AND to the type.
Related to this is JDK-8177557, for which the comment quotes the incorrect JLS section.
Other related issues:
-
- JDK-8077585
- JDK-8223936: Which covers the case where the annotation is not admissible as TYPE_USE
-
- relates to
-
JDK-8177557 9.7.4: Inconsistent treatment of annotated method returns
-
- Open
-