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

Invalid RuntimeVisibleTypeAnnotations for annotation on anonymous class type parameter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 12
    • None
    • tools
    • None
    • b18

      In the following example the method 'f' has an incorrect CLASS_EXTENDS RuntimeVisibleTypeAnnotations attribute. The annotation is actually associated with the type argument of an anonymous class inside the method body.

      ===
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;
      import java.util.concurrent.Callable;

      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
      @interface Foo {}

      class T {
        private void f() {
          new Callable<@Foo Object>() {
            public Object call() {
              return null;
            }
          };
        }
      }
      ===

      $ javac -fullversion T.java && /google/data/ro/
      javac full version "11-ea+3"
      $ javap -p -v T
      ...

        private void f();
          descriptor: ()V
          flags: (0x0002) ACC_PRIVATE
          Code:
            stack=3, locals=1, args_size=1
               0: new #2 // class T$1
               3: dup
               4: aload_0
               5: invokespecial #3 // Method T$1."<init>":(LT;)V
               8: pop
               9: return
            LineNumberTable:
              line 13: 0
              line 18: 9
          RuntimeVisibleTypeAnnotations:
            0: #13(): CLASS_EXTENDS, type_index=0, location=[TYPE_ARGUMENT(0)]
              Foo

            cushon Liam Miller-Cushon
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: