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

(reflect) toGenericString fails to print bounds of type variables on generic methods

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 12
    • core-libs
    • None
    • behavioral
    • minimal
    • Those parsing the toGenericString output directly will have to adjust their code in some case.
    • Java API

      Summary

      The toGenericString output does not include information about the bounds of type variables; this information should be included when type variables are declared in type or methods/constructors.

      Problem

      Relevant type information is omitted from the toGenericString output.

      Solution

      Adjust the spec and implementation to include the bounds when they are informative, meaning if a set of bounds of a type variable is just "extends Object", printing that is omitted since it is equivalent to not have an explicit bound.

      Specification

      --- old/src/java.base/share/classes/java/lang/Class.java    2018-10-11 17:46:31.940000000 -0700
      +++ new/src/java.base/share/classes/java/lang/Class.java    2018-10-11 17:46:31.756000000 -0700
      @@ -200,7 +200,8 @@
            * and {@code class}, {@code enum}, {@code interface}, or
            * <code>&#64;</code>{@code interface}, as appropriate), followed
            * by the type's name, followed by an angle-bracketed
      -     * comma-separated list of the type's type parameters, if any.
      +     * comma-separated list of the type's type parameters, if any,
      +     * including informative bounds on the type parameters, if any.
            *
            * A space is used to separate modifiers from one another and to
            * separate any modifiers from the kind of type. The modifiers
      
      --- old/src/java.base/share/classes/java/lang/reflect/Constructor.java  2018-10-11 17:46:32.364000000 -0700
      +++ new/src/java.base/share/classes/java/lang/reflect/Constructor.java  2018-10-11 17:46:32.196000000 -0700
      @@ -382,7 +382,8 @@
            * including type parameters.  The string is formatted as the
            * constructor access modifiers, if any, followed by an
            * angle-bracketed comma separated list of the constructor's type
      -     * parameters, if any, followed by the fully-qualified name of the
      +     * parameters, if any, including  informative bounds of the
      +     * type parameters, if any, followed by the fully-qualified name of the
            * declaring class, followed by a parenthesized, comma-separated
            * list of the constructor's generic formal parameter types.
            *
      
      --- old/src/java.base/share/classes/java/lang/reflect/Method.java   2018-10-11 17:46:33.184000000 -0700
      +++ new/src/java.base/share/classes/java/lang/reflect/Method.java   2018-10-11 17:46:33.008000000 -0700
      @@ -436,10 +436,11 @@
           }
      
           /**
      -     * Returns a string describing this {@code Method}, including
      -     * type parameters.  The string is formatted as the method access
      +     * Returns a string describing this {@code Method}, including type
      +     * parameters.  The string is formatted as the method access
            * modifiers, if any, followed by an angle-bracketed
            * comma-separated list of the method's type parameters, if any,
      +     * including informative bounds of the type parameters, if any,
            * followed by the method's generic return type, followed by a
            * space, followed by the class declaring the method, followed by

            darcy Joe Darcy
            ahe Peter Ahe
            Brian Burkhalter, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: