Spec clarification, where are annotations without @Target applicable?
Brian Goetz
brian.goetz at oracle.com
Mon Oct 19 10:34:26 UTC 2020
The JLS 13 text seems right to me. The ambiguity between deco and type contexts makes “all contexts” problematic. I don’t recall this change as a “decision”.
Sent from my iPad
> On Oct 19, 2020, at 5:49 AM, Joel Borggrén-Franck <joel.p.borggren-franck at oracle.com> wrote:
>
> Hello JLS experts,
>
> When reviewing the proposed fix for annotations not being applicable to modules by default [3] I noticed that the Javadoc [1] and JLS wording [2] for which annotation contexts are applicable by default have diverged since Java 14. The javaoc for j.l.a.Target keeps the old wording:
>
> "If an @Target meta-annotation is not present on an annotation type T, then an annotation of type T may be written as a modifier for any declaration except a type parameter declaration."
>
> While the JLS since 14 states:
>
> "If an annotation of type java.lang.annotation.Target is not present on the declaration of an annotation type T, then T is applicable in all nine declaration contexts and in all 16 type contexts."
>
> vs JLS 13:
>
> "If an annotation of type java.lang.annotation.Target is not present on the declaration of an annotation type T, then T is applicable in all declaration contexts except type parameter declarations, and in no type contexts.
>
> These contexts are the syntactic locations where annotations were allowed in Java SE 7."
>
> I can't find any mention of this change in a CSR so it is not yet clear to me if the Javadoc or the JLS needs to be updated.
>
> cheers
> /Joel
>
> [1] https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/annotation/Target.html
> [2] https://docs.oracle.com/javase/specs/jls/se15/html/jls-9.html#jls-9.6.4.1
> [3] https://github.com/openjdk/jdk/pull/622
>
More information about the compiler-dev
mailing list