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

java.lang.reflect.Parameter.getAnnotations() fails for inner classes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 8
    • 8
    • core-libs

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      java.lang.reflect.Parameter.getAnnotations() fails for inner classes with

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
      at java.lang.reflect.Parameter.getDeclaredAnnotations(Parameter.java:300)
      at java.lang.reflect.Parameter.getAnnotations(Parameter.java:328)
      at Err.main(Err.java:30)

      Looks like a deeper bug in how annotations on inner classes are handled since:
              System.out.println(p.getDeclaringExecutable().getParameterTypes().length);
      returns 2
      but System.out.println(p.getDeclaringExecutable().getParameterAnnotations().length);
      returns 1



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public class Err {

          public static void main(String[] args) {
              Parameter p = E.class.getConstructors()[0].getParameters()[1];
              p.getAnnotations();
          }

          @Retention(RetentionPolicy.RUNTIME)
          public @interface Ann {}

          public class E {
              public E(@Ann Object o) {}
          }
      }



      REPRODUCIBILITY :
      This bug can be reproduced always.

            emc Eric Mccorkle
            alanb Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: