FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-rc-b104, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux localhost.localdomain 2.6.19 #1 SMP Thu Nov 30 10:17:45 GMT 2006 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The behaviour of ClassLoader.loadClass in JDK6 changed when comparing it to the one in JDK5. It now throws a ClassNotFoundException when "[B" (for byte array) is passed as an argument. In JDK5, the correct Class object would be returned. This is a very nasty regression as far as I can see. I have included a very simple test case that shows the problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I've added a very simple test case that shows the problem in the appropriate box. It should be obvious from the test case, but a summary is:
1) Call ClassLoader.loadClass("[B")
2) A ClassNotFoundException is thrown instead of the relevant class object being returned.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The test should pass, and it does with jdk1.5.0_08.
ACTUAL -
The test fails with a ClassNotFoundException. I am pasting the stack trace in the "Error Message" box.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Stack trace from the test.
java.lang.ClassNotFoundException: [B
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 j.lang.test.LoadClassTest.testLoadClassWithBytePrimitiveArray(LoadClassTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package j.lang.test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class LoadClassTest {
@Test
public void testLoadClassWithBytePrimitiveArray() throws Exception {
String byteArrayBinaryName = byte[].class.getName();
Class c = Thread.currentThread().getContextClassLoader().
loadClass(byteArrayBinaryName);
assertEquals(byte[].class, c);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use JDK 5.0 Update 8.