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

Constructor.getAnnotatedParameterTypes returns wrong value

    XMLWordPrintable

    Details

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                darcy Joe Darcy
                Reporter:
                evotchen Elena Votchennikova (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                  Dates

                  Due:
                  Created:
                  Updated:
                  Resolved: