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

no-@Target annotations should be applicable to type parameter declarations

    XMLWordPrintable

Details

    • b21

    Description

      This was reported on: https://stackoverflow.com/q/75667924/4297386

      After the changes in https://bugs.openjdk.org/browse/JDK-8261610, JLS 9.6.4.1 reads:

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

      'all declaration contexts' includes type parameter declarations.

      javac still incorrectly rejects @Target-less annotations on type parameter declarations:

      ```
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;

      @Retention(RetentionPolicy.RUNTIME)
      @interface A {}

      class B<@A C> {}
      ```

      $ javac -fullversion
      javac full version "20-ea+35-2342"
      $ javac B.java
      B.java:7: error: annotation @A not applicable in this type context
      class B<@A C> {}
              ^
      1 error

      Attachments

        Issue Links

          Activity

            People

              cushon Liam Miller-Cushon
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: