[jboss-user] [JBoss Cache: Core Edition] - Re: ClassNotFoundException during deserialisation

mbrade do-not-reply at jboss.com
Tue Aug 26 02:15:38 EDT 2008

I'm affraid I don't have a real JUnit Test for that. But it's easy to reproduce you need an DB or an File Cache to serialize and persist the objects.

Now you can store for example Integer.TYPE or another primitive. Evict it from memory and load it again. You should get an Exception during deserialisation. (In my case I try to store a methodname, classname and an array of classes. All together in one class)
The Test should run with Suns defaultClassloader. If you have a special one (Maybee one from an ApplicationServer) this bug might be fixed by using another Classloader.

Btw: If you compare MarshalledValueInputStream and ObjectInputStream would see that the MarshalledValueInputStream overrides resolveClass:

  |    protected Class resolveClass(ObjectStreamClass v)
  |       throws IOException, ClassNotFoundException
  |    {
  |       ClassLoader loader = Thread.currentThread().getContextClassLoader();
  |       String className = v.getName();
  |       return loader.loadClass(className);
  |    }

Thats the code from ObjectInputStream in Java 1.6:

  | ...
  |     private static final HashMap primClasses = new HashMap(8, 1.0F);
  |     static {
  | 	primClasses.put("boolean", boolean.class);
  | 	primClasses.put("byte", byte.class);
  | 	primClasses.put("char", char.class);
  | 	primClasses.put("short", short.class);
  | 	primClasses.put("int", int.class);
  | 	primClasses.put("long", long.class);
  | 	primClasses.put("float", float.class);
  | 	primClasses.put("double", double.class);
  | 	primClasses.put("void", void.class);
  |     }
  | ...
  |     protected Class<?> resolveClass(ObjectStreamClass desc)
  | 	throws IOException, ClassNotFoundException
  |     {
  | 	String name = desc.getName();
  | 	try {
  | 	    return Class.forName(name, false, latestUserDefinedLoader());
  | 	} catch (ClassNotFoundException ex) {
  | 	    Class cl = (Class) primClasses.get(name);
  | 	    if (cl != null) {
  | 		return cl;
  | 	    } else {
  | 		throw ex;
  | 	    }
  | 	}
  |     }

The fallback for the primitives is missing. loadClass() doesn't work for primitives with Suns Classloaders.

I'll try to set the classloader on the region and give feedback but as you can see the ContextClassLoader of the current Thread is used (I hope it's always the right one).

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172474#4172474

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172474

More information about the jboss-user mailing list