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

mbrade do-not-reply at jboss.com
Fri Aug 22 10:51:30 EDT 2008


Hello

I looked at the source code and it is impossible to fix that bug by writing your own Marshaller. 
The VersionAwareMarshaller is used to work as a wrapper for the Marshaller you define. It creates a org.jboss.util.stream.MarshalledValueInputStream as an replacement for Suns java.io.ObjectInputStream. The MarshalledValueInputStream seems to have problems with primitives. It should take aware of a ClassNotFoundException and check if the name of the class which should be returned matches one of the primitives.

I looked at the source code of ObjectInputStream of the JDK 1.6 and noticed that they have fixed the bug.

I could fix this bug by writting and setting my own classloader in the DefaultCacheFactory.

  | DefaultCacheFactory factory = new DefaultCacheFactory();
  | factory.setDefaultClassLoader( new MyClassLoader() );
  | ...
  | import java.util.HashMap;
  | 
  | 
  | @SuppressWarnings("unchecked")
  | public class MyClassLoader extends ClassLoader {
  |     //from java.io.ObjectInputStream
  |     private static final HashMap primClasses = new HashMap();
  |     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);
  |     }
  |       
  | 
  |     public MyClassLoader() {
  |         super(PrimitiveAwareClassLoader.class.getClassLoader());
  |     }
  | 
  |     public MyClassLoader(ClassLoader parent) {
  |         super(parent);
  |     }
  | 
  |     @Override
  |     public Class<?> loadClass(String name) throws ClassNotFoundException {
  |         try{
  |             return super.loadClass(name);
  |         }catch(ClassNotFoundException cnfe){
  |             Class cl = (Class) primClasses.get(name);
  |             if (cl != null) {
  |                 return cl;
  |             } else {
  |                 throw cnfe;
  |             }
  |         }
  |     }   
  | 
  | }
  | 

Maybee I can help someone with that.



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

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



More information about the jboss-user mailing list