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

(reflect) no type annotations on a Parameter representing the annotated receiver

XMLWordPrintable

      Executable.getParameters()[0].getAnnotaetdType() has no type annotations for an annotated receiver.

      Minimized repro:

      ----- 8< ------
      import java.lang.annotation.*;
      import java.lang.reflect.*;
      import java.util.Arrays;

      public class IsRecvAParam {

         @Target(ElementType.TYPE_USE)
         @Retention(RetentionPolicy.RUNTIME)
         @interface A {
         }

         class Foo {
            Foo(@A IsRecvAParam IsRecvAParam.this) {
            }
         }

         public static void main(String args[]) {
            Constructor<?> cons = IsRecvAParam.Foo.class.getDeclaredConstructors()[0];

            System.out.println("TypeAnnotations on:");
            System.out.println("getAnnotatedParameterTypes()[0]: " + Arrays.asList(cons.getAnnotatedParameterTypes()[0].getAnnotations()) +
                                         " //correct no type annotation here");
            System.out.println("getAnnotatedReciver(): " + Arrays.asList(cons.getAnnotatedReceiverType().getAnnotations()) + " //correct");

            System.out.println("getParameters()[0].getAnnotatedType(): " + Arrays.asList(cons.getParameters()[0].getAnnotatedType().getAnnotations()) +
                                         " //error");
         }
      }
      ----- 8< ------

            vromero Vicente Arturo Romero Zaldivar
            jfranck Joel Borggrén-Franck (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: