JDK-5033583 : (reflect) need toGenericString methods
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-04-19
  • Updated: 2019-12-05
  • Resolved: 2004-05-11
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.
Other
5.0 b51Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Various classes in java.lang.reflect have been updated in Tiger with "generic" versions of existing methods to provide generic and non-generic views of their type information; e.g. getGenericExceptionTypes, getGenericParameterTypes, etc.  However, the toString methods of these classes still only print out non-generic type information about the objects.  A toGenericString method would allow a more accurate representation of the type to be displayed.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b51 tiger-beta2
14-06-2004

SUGGESTED FIX src/share/classes/java/lang/reflect>sccs sccsdiff -r1.47 -r1.48 Method.java ------- Method.java ------- 323,324c323,326 < if (getGenericSignature() != null) < return getGenericInfo().getExceptionTypes(); --- > Type[] result; > if (getGenericSignature() != null && > ((result = getGenericInfo().getExceptionTypes()).length > 0)) > return result; 329,330d330 < < 413a414,500 > } > } > return sb.toString(); > } catch (Exception e) { > return "<" + e + ">"; > } > } > > /** > * Returns a string describing this <code>Method</code>, 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, > * followed by the method's generic return type, followed by a > * space, followed by the class declaring the method, followed by > * a period, followed by the method name, followed by a > * parenthesized, comma-separated list of the method's generic > * formal parameter types. A space is used to separate access > * modifiers from one another and from the type parameters or > * return type. If there are no type parameters, the type > * parameter list is elided; if the type parameter list is > * present, a space separates the list from the class name. If > * the method is declared to throw exceptions, the parameter list > * is followed by a space, followed by the word throws followed by > * a comma-separated list of the generic thrown exception types. > * If there are no type parameters, the type parameter list is > * elided. > * > * <p>The access modifiers are placed in canonical order as > * specified by "The Java Language Specification". This is > * <tt>public</tt>, <tt>protected</tt> or <tt>private</tt> first, > * and then other modifiers in the following order: > * <tt>abstract</tt>, <tt>static</tt>, <tt>final</tt>, > * <tt>synchronized</tt> <tt>native</tt>. > * > * @return a string describing this <code>Method</code>, > * include type parameters > * > * @since 1.5 > */ > public String toGenericString() { > try { > StringBuilder sb = new StringBuilder(); > int mod = getModifiers(); > if (mod != 0) { > sb.append(Modifier.toString(mod) + " "); > } > Type[] typeparms = getTypeParameters(); > if (typeparms.length > 0) { > boolean first = true; > sb.append("<"); > for(Type typeparm: typeparms) { > if (!first) > sb.append(","); > if (typeparm instanceof Class) > sb.append(((Class)typeparm).getName()); > else > sb.append(typeparm.toString()); > first = false; > } > sb.append("> "); > } > > Type genRetType = getGenericReturnType(); > sb.append( ((genRetType instanceof Class)? > Field.getTypeName((Class)genRetType):genRetType.toString()) + " "); > > sb.append(Field.getTypeName(getDeclaringClass()) + "."); > sb.append(getName() + "("); > Type[] params = getGenericParameterTypes(); > for (int j = 0; j < params.length; j++) { > sb.append((params[j] instanceof Class)? > Field.getTypeName((Class)params[j]): > (params[j].toString()) ); > if (j < (params.length - 1)) > sb.append(","); > } > sb.append(")"); > Type[] exceptions = getGenericExceptionTypes(); > if (exceptions.length > 0) { > sb.append(" throws "); > for (int k = 0; k < exceptions.length; k++) { > sb.append((exceptions[k] instanceof Class)? > ((Class)exceptions[k]).getName(): > exceptions[k].toString()); > if (k < (exceptions.length - 1)) > sb.append(","); src/share/classes/java/lang/reflect>sccs sccsdiff -r1.47 -r1.48 Constructor.java ------- Constructor.java ------- 270,271c270,273 < if (getSignature() != null) < return getGenericInfo().getExceptionTypes(); --- > Type[] result; > if (getSignature() != null && > ( (result = getGenericInfo().getExceptionTypes()).length > 0 )) > return result; 347a350,426 > } > } > return sb.toString(); > } catch (Exception e) { > return "<" + e + ">"; > } > } > > /** > * Returns a string describing this <code>Constructor</code>, > * 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 > * declaring class, followed by a parenthesized, comma-separated > * list of the constructor's generic formal parameter types. A > * space is used to separate access modifiers from one another and > * from the type parameters or return type. If there are no type > * parameters, the type parameter list is elided; if the type > * parameter list is present, a space separates the list from the > * class name. If the constructor is declared to throw > * exceptions, the parameter list is followed by a space, followed > * by the word &quot;<tt>throws</tt>&quot; followed by a > * comma-separated list of the thrown exception types. > * > * <p>The only possible modifiers for constructors are the access > * modifiers <tt>public</tt>, <tt>protected</tt> or > * <tt>private</tt>. Only one of these may appear, or none if the > * constructor has default (package) access. > * > * @return a string describing this <code>Constructor</code>, > * include type parameters > * > * @since 1.5 > */ > public String toGenericString() { > try { > StringBuilder sb = new StringBuilder(); > int mod = getModifiers(); > if (mod != 0) { > sb.append(Modifier.toString(mod) + " "); > } > Type[] typeparms = getTypeParameters(); > if (typeparms.length > 0) { > boolean first = true; > sb.append("<"); > for(Type typeparm: typeparms) { > if (!first) > sb.append(","); > if (typeparm instanceof Class) > sb.append(((Class)typeparm).getName()); > else > sb.append(typeparm.toString()); > first = false; > } > sb.append("> "); > } > sb.append(Field.getTypeName(getDeclaringClass())); > sb.append("("); > Type[] params = getGenericParameterTypes(); > for (int j = 0; j < params.length; j++) { > sb.append((params[j] instanceof Class)? > Field.getTypeName((Class)params[j]): > (params[j].toString()) ); > if (j < (params.length - 1)) > sb.append(","); > } > sb.append(")"); > Type[] exceptions = getGenericExceptionTypes(); > if (exceptions.length > 0) { > sb.append(" throws "); > for (int k = 0; k < exceptions.length; k++) { > sb.append((exceptions[k] instanceof Class)? > ((Class)exceptions[k]).getName(): > exceptions[k].toString()); > if (k < (exceptions.length - 1)) > sb.append(","); src/share/classes/java/lang/reflect>sccs sccsdiff -r1.39 -r1.40 Field.java ------- Field.java ------- 275a276,304 > * Returns a string describing this <code>Field</code>, including > * its generic type. The format is the access modifiers for the > * field, if any, followed by the generic field type, followed by > * a space, followed by the fully-qualified name of the class > * declaring the field, followed by a period, followed by the name > * of the field. > * > * <p>The modifiers are placed in canonical order as specified by > * "The Java Language Specification". This is <tt>public</tt>, > * <tt>protected</tt> or <tt>private</tt> first, and then other > * modifiers in the following order: <tt>static</tt>, <tt>final</tt>, > * <tt>transient</tt>, <tt>volatile</tt>. > * > * @return a string describing this <code>Field</code>, including > * its generic type > * > * @since 1.5 > */ > public String toGenericString() { > int mod = getModifiers(); > Type fieldType = getGenericType(); > return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) > + ((fieldType instanceof Class) ? > getTypeName((Class)fieldType): fieldType.toString())+ " " > + getTypeName(getDeclaringClass()) + "." > + getName()); > } > > /** ###@###.### 2004-04-30
30-04-2004

EVALUATION A fine idea. ###@###.### 2004-04-18
18-04-2004