Deserialization Problem on Linux with Custom ClassLoader

I am writing a Vector object to a file like this:

ObjectOutputStream out =new ObjectOutputStream(new FileOutputStream(file));

out.writeObject(vector);

out.close();

To read it back using a custom ClassLoader I have

ObjectInputStream in =new ObjectInputStream(new FileInputStream(file)){

protected Class<?> resolveClass(ObjectStreamClass desc)throws ClassNotFoundException{

return classLoader.loadClass(desc.getName());

}

};

vector = (Vector<T>)in.readObject();

in.close();

This works fine on Windows, but not on Linux. The problem is that my custom ClassLoader has to find a class named "[Ljava.lang.Object;" which is, as far as I have found out, usually handled by the default ClassLoader of the JVM. The ClassNotFoundException contains this stack trace:

java.lang.ClassNotFoundException:class'[Ljava.lang.Object;' not found by FileClassLoader.

at ch.ethz.dcg.plugin.classloader.FileClassLoader.findClass(FileClassLoader.java:140)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at ch.ethz.dcg.util.LazyBackupedVector$1.resolveClass(LazyBackupedVector.java:141)

at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)

at java.io.ObjectInputStream.readClassDesc(Unknown Source)

at java.io.ObjectInputStream.readArray(Unknown Source)

at java.io.ObjectInputStream.readObject0(Unknown Source)

at java.io.ObjectInputStream.defaultReadFields(Unknown Source)

at java.io.ObjectInputStream.readSerialData(Unknown Source)

at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

at java.io.ObjectInputStream.readObject0(Unknown Source)

at java.io.ObjectInputStream.readObject(Unknown Source)

at ch.ethz.dcg.util.LazyBackupedVector.loadFile(LazyBackupedVector.java:145)

Can anyone explain the behavior to me? Am I doing something wrong? Thanks!

[2392 byte] By [kenoaa] at [2007-11-27 2:30:11]
# 1

I just realized that this issue is not Linux/Windows specific but Java 6/5 specific. That is, using Java 5 it works, using Java 6 it doesn't work.

And another finding: if you copy the saved file to a Java 5 installation, reading works fine, no ClassNotFoundException.

Has anything changed between Java 5 and 6?

kenoaa at 2007-7-12 2:43:42 > top of Java-index,Core,Core APIs...
# 2
Just another update. When storing and loading a HashMap with the same load/save mechanism, it works fine. However, I write different Objects.
kenoaa at 2007-7-12 2:43:42 > top of Java-index,Core,Core APIs...
# 3

Have you found anything more about this problem?

I too have an issue that works fine when both server and client are 1.5.X but if the client is 1.6.0_1 then I have a random failure during the serializing of objects back to the client. From that point on, I get a class not found exception because the cached classes are apparently corrupt.

http://forum.java.sun.com/thread.jspa?threadID=5167958&tstart=0

AlfredTheGreya at 2007-7-12 2:43:42 > top of Java-index,Core,Core APIs...
# 4
I haven't found the real reason, but I found a work-around for my problem. I was able to remove the dependency on a custom class loader and then it worked. But this is really only a work-around and does not fix the problem :-(. I would love to know what is going on.
kenoaa at 2007-7-12 2:43:42 > top of Java-index,Core,Core APIs...