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

Repeated type-annotation on type arg in method reference not written to class file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 8
    • 8
    • tools

      A repeated type-annotation on a type argument in a method reference is not written to the class file.
      A single type-annotation is. In the sample below, there is one RuntimeVisibleTypeAnnotations:
            0: #25(): METHOD_REFERENCE_TYPE_ARGUMENT, offset=42, type_index=0
      - - - - - - - - - - - - - - - - - - - - - -
      import java.lang.annotation.*;
      import static java.lang.annotation.RetentionPolicy.*;
      import static java.lang.annotation.ElementType.*;
      import java.util.List;
      import java.util.ArrayList;

      //case6:(repeating) type annotations on type parm in method reference.
      class Test6{
          interface PrintString { void print(String s); }
          public void printArray(Object[] oa, PrintString ps) {
              for(Object o : oa ) ps.print(o.toString());
          }

          public void test() {
              Integer[] intarray = {1,2,3,4,5};
              printArray(intarray, TPrint::<@A String>print); //okay
              printArray(intarray, TPrint::<@A @A String>print); //no annotations in class file
              printArray(intarray, TPrint::<@A @A @B String>print); //okay
              printArray(intarray, TPrint::<@A @A @B @B String>print); //no annotations in class file

          }

          public static void main(String... args) {new Test6().test(); }
      }

      class TPrint {
         public static <T> void print(T t) { System.out.println( t.toString()); }
      }

      @Retention(RUNTIME) @Target({TYPE_USE,TYPE}) @Repeatable( AC.class ) @interface A { }
      @Retention(RUNTIME) @Target({TYPE_USE,TYPE}) @interface AC { A[] value(); }

      @Retention(RUNTIME) @Target({TYPE_USE,TYPE}) @Repeatable( BC.class ) @interface B { }
      @Retention(RUNTIME) @Target({TYPE_USE,TYPE}) @interface BC { B[] value(); }

            vromero Vicente Arturo Romero Zaldivar
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: