Spec clarification, where are annotations without @Target applicable?

Werner Dietl wdietl at gmail.com
Mon Oct 19 13:11:54 UTC 2020


I think this is a relevant discussion:

https://mail.openjdk.java.net/pipermail/compiler-dev/2019-August/013666.html

https://mail.openjdk.java.net/pipermail/compiler-dev/2019-September/013715.html

cu, WMD.

On Mon, Oct 19, 2020 at 6:34 AM Brian Goetz <brian.goetz at oracle.com> wrote:

> 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
> >
>
>

-- 
https://ece.uwaterloo.ca/~wdietl/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20201019/e8d66c12/attachment.htm>


More information about the compiler-dev mailing list