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

AnnotatedType.getType() of a Executable parameters may return wrong type

XMLWordPrintable

    • b17
    • x86_64
    • linux
    • Verified

        FULL PRODUCT VERSION :
        build 1.8.0-b132

        ADDITIONAL OS VERSION INFORMATION :
        Linux ivostmaina 3.13.6-gentoo #1 SMP Thu Mar 20 02:22:16 CET 2014 x86_64 AMD FX(tm)-8350 Eight-Core Processor AuthenticAMD GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        This Bug maybe related to Bug: https://bugs.openjdk.java.net/browse/JDK-8038994

        If getAnnotatedParameterTypes() is used on an Exectuable instance (Method or Constructor) which have got generic type parameters, the returned AnnotatedType.getType() may return the class type instead of a ParameterizedType instance. getGenericParameterTypes() returns the right types.

        For all i, I expect
        Exectuable.getAnnotatedParameterTypes()[i].getType() equals Exectuable.getGenericParameterTypes()[i]

        Example:
        class TestClass {
          void foobar(List<T> x);
        }

        Method m; is the reflection object for method "foobar"
        m.getAnnotatedParameterTypes[0].getType() returns List.class instead of an instance to a ParameterizedType instance
        m.getGenericParameterTypes()[0] returns as expected a ParameterizedType instance

        REGRESSION. Last worked in version 8

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        see test case


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        @Test
        public void java8_executable_getAnnotatedParameterTypes_v1()
        throws NoSuchMethodException, SecurityException {

        class MyClass<T> {

        }

        class MySecondClass<T> {

        @SuppressWarnings("unused")
        public MyClass<T> get(MyClass<T> p) {
        return p;
        }

        }

        Method method = MySecondClass.class.getMethod("get", MyClass.class);

        AnnotatedType at = method.getAnnotatedParameterTypes()[0];
        // at.getType() is MyClass.class in build 1.8.0-b132

        Type t = method.getGenericParameterTypes()[0];
        // t is ParameterizedType of MyClass

        assertEquals(t, at.getType());
        assertEquals(at.getType(), t);
        }
        ---------- END SOURCE ----------

        SUPPORT :
        YES

              jfranck Joel Borggrén-Franck (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: