JDK-6434149 : (cl) ClassLoader.loadClass() throws java.lang.ClassNotFoundException: [Ljava.lang.String; in JDK 6.0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:class_loading
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic,linux,solaris_10,windows_xp
  • CPU: generic,x86,sparc
  • Submitted: 2006-06-05
  • Updated: 2014-01-14
  • Resolved: 2014-01-14
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
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
ClassLoader.loadClass does not support array syntax. JDK-6516909 clarifies this in the ClassLoader spec. Close this bug as a dup of JDK-6516909.
14-01-2014

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.
10-04-2013

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).
18-08-2009

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.
17-08-2009

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