javac fails to reject inadmissable type annotations

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P3
    • tbd
    • Affects Version/s: None
    • Component/s: tools

      javac correctly rejects the following type annotation on `One.Inner`, since annotations on `One` are not admissible (JLS 9.7.4).

      ```
      import static java.lang.annotation.ElementType.TYPE_USE;

      import java.lang.annotation.Target;

      abstract class One {
        @Target(TYPE_USE)
        @interface A {}

        static class Inner {}

        @A One.Inner f;
      }
      ```

      One.java:11: error: scoping construct cannot be annotated with type-use annotation: @One.A
        @A One.Inner f;
              ^
      1 error

      However in this example the annotation has been modified to target both 'FIELD' and 'TYPE_USE' locations, and javac both emits the annotation as a declaration on the field, and as a type annotation on `One` (which is incorrect):

      ```
      import static java.lang.annotation.ElementType.FIELD;
      import static java.lang.annotation.ElementType.TYPE_USE;

      import java.lang.annotation.Target;

      abstract class Two {
        @Target({FIELD, TYPE_USE})
        @interface A {}

        static class Inner {}

        @A Two.Inner f;
      }
      ```

        Two$Inner f;
          descriptor: LTwo$Inner;
          flags: (0x0000)
          RuntimeInvisibleAnnotations:
            0: #12()
              Two$A
          RuntimeInvisibleTypeAnnotations:
            0: #12(): FIELD
              Two$A

      I think the compiler should reject both inputs.

            Assignee:
            Unassigned
            Reporter:
            Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: