JDK-6516909 : (cl spec) ClassLoader.loadClass() clarification to indicate it shouldn't be used for array classes
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:class_loading
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-01-24
  • Updated: 2017-09-26
  • Resolved: 2014-01-23
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 9
9 b03Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8175391 :  
Description
A DESCRIPTION OF THE PROBLEM :
As a follow up to the evaluation in bug #6446627 I am requesting that the Javadoc for ClassLoader.loadClass(String, boolean) be updated to explicitly note that parameter "name" does not accept array classes and Class.forName() should be used instead.


URL OF FAULTY DOCUMENTATION :
http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#loadClass(java.lang.String,%20boolean)

Comments
The "Binary Name" section of the ClassLoader class description will be updated for clarification: + * {@code Class} objects for array classes are not created by {@code ClassLoader}; + * use the {@link Class#forName} method instead. In addition, ClassLoader.loadClass doesn't allow array syntax since JDK 6. The workaround "sun.lang.ClassLoader.allowArraySyntax" system property will be removed in JDK 9.
14-01-2014

EVALUATION Generally speaking reflective loading of a class by name should be accomplished by using this static method in java.lang.Class: public static Class<?> forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException The ClassLoader.loadClass() method is more typically used for class loader delegation. Invocation of Class.forName() may eventually invoke ClassLoader.loadClass() after handling VM name resolution. In particular, for array classes, this would involve loading the array's component type. Thus, we highly recommend replacement of this code: myClassLoader.loadClass(className); With this code: Class.forName(className,false,myClassLoader); An appropriate usage note describing the above recommended practice should be added to the ClassLoader javadoc.
31-07-2007