JDK-6304578 : (reflect) toGenericString fails to print bounds of type variables on generic methods
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-01
  • Updated: 2019-04-22
  • Resolved: 2018-11-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12 b19Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Description
As demonstrated by the program below, java.lang.reflect.Method.toGenericString
doesn't print bounds on type variables on generic methods.  Run the program like this:

$ java Test java.util.Collections max java.util.Collection java.util.Collections
max
java.util.Collection
public static <T> T java.util.Collections.max(java.util.Collection<? extends T>)

The output should have been:

max
java.util.Collection
public static <T extends Object & Comparable<? super T>> T java.util.Collections.max(java.util.Collection<? extends T>)

import java.lang.reflect.*;
 
public class Test {
    public static void main(String... args) throws ClassNotFoundException, NoSuchMethodException {
        for (int i=0; i<args.length; i++) System.out.println(args[i]);
        String cName = args[0];
        String mName = args[1];
        Class<?> c = Class.forName(cName);
        Class<?>[] cs = new Class<?>[args.length - 2];
        for (int i=0; i<args.length-2; i++) cs[i] = Class.forName(args[i+2]);
        Method m = c.getMethod(mName, cs);
        System.out.println(m.toGenericString());
    }
}

Comments
Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-October/056030.html
12-10-2018