commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From René Link (Created) (JIRA) <>
Subject [jira] [Created] (LANG-788) SerializationUtils throws ClassNotFoundException when cloning of primitive classes
Date Sat, 11 Feb 2012 12:37:59 GMT
SerializationUtils throws ClassNotFoundException when cloning of primitive classes

                 Key: LANG-788
             Project: Commons Lang
          Issue Type: Bug
    Affects Versions: 3.1
            Reporter: René Link

If a serializable object contains a reference to a primitive class, e.g. int.class or int[].class,
the SerializationUtils throw a ClassNotFoundException when trying to clone that object.

import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;

public class SerializationUtilsTest {

	public void primitiveTypeClassSerialization(){
		Class<?> primitiveType = int.class;
		Class<?> clone = SerializationUtils.clone(primitiveType);
		assertEquals(primitiveType, clone);

The problem was already reported as a java bug
and ObjectInputStream is fixed since java version 1.4.
The SerializationUtils problem arises because the SerializationUtils internally use the ClassLoaderAwareObjectInputStream
that overrides the ObjectInputStream's
resoleClass method without delegating to the super method in case of a ClassNotFoundException.

I understand the intention of the ClassLoaderAwareObjectInputStream, but this implementation
should also implement a fallback to the original implementation.

For example:
        protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException,
ClassNotFoundException {
            String name = desc.getName();
            try {
                return Class.forName(name, false, classLoader);
            } catch (ClassNotFoundException ex) {
            	try {
            	     return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
            	} catch (Exception e) {
		     return super.resolveClass(desc);

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message