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

AnnotatedWildcardType.getAnnotatedUpperBounds() returns wrong result if wildcard declares no upper bound

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 8
    • core-libs
    • None

      According to the spec for j.l.r.WildcardType:
      "Note that if no upper bound is explicitly declared, the upper bound is
      Object."
      And looks like this should be also true for j.l.r.AnnotatedWildcardType.

      If we have wildcard without definition of lower and upper
      bounds, AnnotatedWildcardType.getAnnotatedUpperBounds().length will
      return 1.

      Minimized test:
      -------------------------------------------------------------------------------
      public class Test {

           public Test(List<? super String> p) {}

           public static void main(String[] args) throws NoSuchMethodException {
               Constructor constructor = Test.class.getConstructor(List.class);
               AnnotatedParameterizedType at = (AnnotatedParameterizedType)
      constructor.getAnnotatedParameterTypes()[0];
               System.out.println(((AnnotatedWildcardType)
      at.getAnnotatedActualTypeArguments()[0]).getAnnotatedUpperBounds().length);

               ParameterizedType t = (ParameterizedType)
      constructor.getGenericParameterTypes()[0];
               System.out.println(((WildcardType)
      t.getActualTypeArguments()[0]).getUpperBounds().length);
           }

      }
      -------------------------------------------------------------------------------


      Output (tested with jdk8u20):
      -------------------------------------------------------------------------------
      0
      1
      -------------------------------------------------------------------------------


      As I understand output should be:
      -------------------------------------------------------------------------------
      1
      1
      -------------------------------------------------------------------------------

            abuckley Alex Buckley
            evotchen Elena Votchennikova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: