JDK-8025806 : java.lang.reflect.Parameter.getAnnotations() fails for inner classes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • Submitted: 2013-10-01
  • Updated: 2013-10-07
  • Resolved: 2013-10-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Duplicate :  
Description
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.
Comments
The root cause of this issue is javac's failure to generate RuntimeVisibleParameterAnnotations entries for synthetic/mandated parameters. This issue is being addressed by another bug. Core reflection does not need to be in the business of guessing where there should be extra parameters because of bad class file data. Closing this as a duplicate.
07-10-2013

This should be fixed by JDK-8024694
07-10-2013

Root cause is javac generates RuntimeVisibleParameterAnnotations without an annotation slot for the synthetic/mandated parameters. This raises a spec question, forwarding to compiler-dev and Alex Buckley.
07-10-2013

Moving from JI to JDK project.
02-10-2013