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

JLS contradiction for annotations with FIELD and TYPE_USE target

    Details

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

      Description

      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


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: