Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261610 Refine no-@Target to mean "applicable in all declaration contexts"



    • Bug
    • Resolution: Fixed
    • P4
    • 17
    • 16
    • specification


      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 (and excluded from no-@Target by JSR 308, wrongly),
      - 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 those new kinds of declarations.

      This meaning overrules JDK-8231435, which in 2019 expanded the meaning from:
        "all declaration contexts that were present in Java SE 7, and no type contexts"
        "all declaration contexts and all type contexts".
      The 2019 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, 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." In effect, JSR 308 had the right idea to disallow type contexts, but went too far in trying to constrain the allowed declaration contexts.


        Issue Links



              abuckley Alex Buckley
              abuckley Alex Buckley
              0 Vote for this issue
              2 Start watching this issue