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

javac wrongly rejects some class literals as annotation element values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8
    • 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 {}
      }

            jjg Jonathan Gibbons
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: