Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
The following minimized test shows that j.l.r.Constructor.getAnnotatedParameterTypes returns wrong array: --------------------------------------------------------------------------- public class MinimizedTest { public static void main(String[] args) throws NoSuchMethodException { Constructor constructor = Inner.class.getConstructor(MinimizedTest.class, Object.class); for (AnnotatedType at : constructor.getAnnotatedParameterTypes()) { System.out.println(at.getType()); System.out.println(Arrays.toString(at.getAnnotations())); System.out.println(); } } class Inner { public Inner(@Anno Object param) {} } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_USE) @interface Anno { } } --------------------------------------------------------------------------- The output will be: --------------------------------------------------------------------------- class MinimizedTest [@MinimizedTest$Anno()] class java.lang.Object [] --------------------------------------------------------------------------- As we can see, the first annotated parameter type has a type MinimizedTest (this is receiver) and has one annotation, but the receiver parameter is not annotated. The second parameter type doesn't has annotation, but it should. Receiver parameter is not a formal parameter, so it's annotated type should not be presented here. The spec of j.l.r.Executable.getAnnotatedParameterTypes says: "Returns an array of AnnotatedType objects that represent the use of types to specify formal parameter types of the method/constructor represented by this Executable. " Checked with JDK9 b53. Failed JCK tests is under development.
|