JDK-6587176 : ClassLoader.findSystemClass() throws CNFException for primitive class names
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-07-31
  • Updated: 2012-01-11
  • Resolved: 2007-07-31
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.6.0_01

ADDITIONAL OS VERSION INFORMATION :
Windows XP SP2 [5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Java method ClassLoader.findSystemClass behavior changed starting in JDK 1.6:

Behavior pre-Java 1.6:
findSystemClass("[[Z")   -> returns "class [[Z" (an array of array primitive)
findSystemClass("[Z")   -> returns "class [Z" (an array primitive)

Behavior post-Java 1.6:
findSystemClass("[[Z")   -> throws ClassNotFoundException
findSystemClass("[Z")   ->  throws ClassNotFoundException


This caused custom serialization code in our application to fail. The idea is that this application can store plug-ins in the serialized objects - this way people who did not have the plug-ins installed could still use the serialized objects.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1 - run the source code in Java 5 and Java 6

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected: No difference between running in Java 5 and Java 6
ACTUAL -
Actual: Running in Java 6 throws a ClassNotFoundException, Java 5 works

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// run this under both JDK 1.5 and JDK 1.6
public class TestClass {
	private static final class MyClassLoader extends ClassLoader {
		public Class myFindClassMethod(String name) throws ClassNotFoundException {
			return findSystemClass(name);
		}
	}

	public static void main(String[] args) {
		System.out.println(System.getProperty("java.version"));
		Object a = new boolean[4][4];
		System.out.println(a.getClass().getName()+ "");
		MyClassLoader loader = new MyClassLoader();
		try {
			Class cl = loader.myFindClassMethod(a.getClass().getName());
			System.out.println("This will only print in Java 1.5.x and lower "+cl);
		} catch (ClassNotFoundException e) {
			// throws exception in Java 1.6.0 and higher
			e.printStackTrace();
		}
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Handle the ClassCastException and use the system class loader to look up primitive array classes.

Release Regression From : 5.0
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION Duplicate. See 6446627 for similar report in serialization. See 6500212 similar report which mentions primitive class names. Both of these reports are closed as duplicates of 6434149 which is an open request to attempt to restore the unreliable behaviour for class syntax. Closing this issue as duplicate of the last bug.
31-07-2007