Release Note: Annotations with No `@Target` Annotation Should Be Applicable to Type Parameter Declarations

XMLWordPrintable

    • Type: Sub-task
    • Resolution: Delivered
    • Priority: P4
    • 21
    • Affects Version/s: 21
    • Component/s: tools

      Prior to JDK 21, the `javac` compiler was not allowing annotations with no `@Target` annotation to be applied to type parameter declarations.

      This is a bug in the `javac` compiler in versions prior to JDK21. [JLS 9.6.4.1](https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html#jls-9.6.4.1) specifies that annotations without an `@Target` annotation are applicable in 'all declaration contexts', which includes type parameter declarations.

      Starting from JDK21, the `javac` compiler will accept code like:

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

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

      class C<@Anno T> {}
      ```

      This change affects compilations targeting `-source`/`--release` 14 and higher.

            Assignee:
            Liam Miller-Cushon
            Reporter:
            Michel Trudeau
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: