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

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

    Details

    • Type: CSR
    • Status: Draft
    • Priority: P4
    • Resolution: Unresolved
    • Fix Version/s: 12
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Those parsing the toGenericString output directly will have to adjust their code in some case.
    • Interface Kind:
      Java API

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                ahe Peter Ahe
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated: