United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6434149 (cl) ClassLoader.loadClass() throws java.lang.ClassNotFoundException: [Ljava.lang.String; in JDK 6.0
JDK-6434149 : (cl) ClassLoader.loadClass() throws java.lang.ClassNotFoundException: [Ljava.lang.String; in JDK 6.0

Details
Type:
Bug
Submit Date:
2006-06-05
Status:
Resolved
Updated Date:
2014-01-14
Project Name:
JDK
Resolved Date:
2014-01-14
Component:
core-libs
OS:
linux,generic,solaris_10,windows_xp
Sub-Component:
java.lang:class_loading
CPU:
x86,sparc,generic
Priority:
P3
Resolution:
Duplicate
Affected Versions:
6
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
Consider this simple test program:

  public class test {

      public static void main(String[] args) throws Exception {

          String[] s = new String[] { "123" };
          String clName = s.getClass().getName();
          test.class.getClassLoader().loadClass(clName);
      }
  }

This runs fine on JDK 1.5, but throws this exception on JDK 6.0:

Exception in thread "main" java.lang.ClassNotFoundException: [Ljava.lang.String;
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at test.main(test.java:7)

                                    

Comments
WORK AROUND

The workaround for applications that depend on this is to set the system property  sun.lang.ClassLoader.allowArraySyntax to true (ie: -Dsun.lang.ClassLoader.allowArraySyntax=true).
                                     
2009-08-18
WORK AROUND

Change classLoader.loadClass(className) into Class.forName(className, false, classLoader).
                                     
2008-11-05
EVALUATION

Please see the evaluation in 4976356 and 6500212. As stated, it was purely accidental that it ever worked. The original intention was to disallow array syntax in jdk5. When changed in jdk5 it caused problems for some applications and so, to give them time to remove their dependency, it was defered to jdk6. Unfortunately this wasn't documented in the compatability notes for that release.
                                     
2009-08-17
The array syntax is not disallowed by default since jdk 6 and we should close this bug as will not fix. JDK 8 seems to be a good time to remove this system property and possibly clarify the javadoc/document if appropriate as JDK-6516909.
                                     
2013-04-10
ClassLoader.loadClass does not support array syntax.  JDK-6516909 clarifies this in the ClassLoader spec.  Close this bug as a dup of JDK-6516909.
                                     
2014-01-14



Hardware and Software, Engineered to Work Together