Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261610

9.6.4.1: Refine no-@Target to mean "applicable in all declaration contexts"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 16
    • Fix Version/s: 17
    • Component/s: specification
    • Labels:

      Description

      Per https://mail.openjdk.java.net/pipermail/compiler-dev/2021-February/016321.html the desired meaning of no-@Target is "all declaration contexts". This meaning includes the type parameter declaration context added in Java SE 8, the module declaration context added in Java SE 9, and the record component declaration context added in Java SE 16. As further kinds of declaration are added to Java, it is intended that "all declaration contexts" will make annotations without an explicit @Target be applicable to them.

      This meaning overrules JDK-8231435, which in 2019 expanded the meaning from:
        "all declaration contexts that were present in Java SE 7"
      to:
        "all declaration contexts and all type contexts".
      The expansion was intended to put type annotations on an equal footing with declaration annotations, but was subsequently seen as a step too far given the disjoint roles typically played by type annotations and declaration annotations. A secondary concern arose in relation to the corner case where annotations in certain ambiguous locations are treated as both type annotations and declaration annotations -- this behavior is long standing and well specified, but bringing all the no-@Target annotations into its orbit was seen as undesirable from a JDK implementation/testing point of view.

      Specifically, 9.6.4.1 should say: "If an annotation of type java.lang.annotation.Target is not present on the declaration of an annotation interface A, then A is applicable in all declaration contexts and in no type contexts."

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              abuckley Alex Buckley
              Reporter:
              abuckley Alex Buckley
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: