javac wrongly rejects some class literals as annotation element values

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: 8
    • Component/s: tools
    • b117
    • Verified

      See the thread "references to non-static types from annotations" at http://mail.openjdk.java.net/pipermail/compiler-dev/2016-April/010104.html.

      In a nutshell, @A(I.class) in the source below is legal, but javac generates a invalid RuntimeVisibleAnnotations attribute for it. javac is effectively interpreting the annotation as @A(Test<T>.I.class) but should interpret it as @A(Test.I.class), which compiles correctly when written in source by hand.

      class Test<T> {
          @Retention(RetentionPolicy.RUNTIME) @interface A { Class<?> value(); }

          // A nested interface is static. The annotation refers to a non-static class.
          @A(I.class) interface C {}

          class I {}
      }

            Assignee:
            Jonathan Gibbons
            Reporter:
            Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: