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

Incorrect attribution of annotations on fields in anonymous classes

XMLWordPrintable

    • Verified

      When compiling the code below, the field 'data' has 2 RuntimeVisibleTypeAnnotations, while the field in the anonymous class, 'data2' has3 RuntimeVisibleTypeAnnotations.
      If there are 2 (such as @A @B data2) it has 6 (rather than 4). A complete test case is attached.
      The same is true for methods.

          class testclass {
              @C String data = "test";
              void mtest( testclass t){ }
              public void test() {
                  mtest( new testclass() {
                           @D String data2 = "test";
                      });
              }
          }

          @Retention(RUNTIME)
          @Target({TYPE_USE,FIELD})
          @interface C { }

          @Retention(RUNTIME)
          @Target({TYPE_USE,FIELD})
          @interface D { }

            ssides Steve Sides
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: