-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2beta4
-
sparc
-
solaris_2.5
-
Verified
Name: avC70361 Date: 02/11/98
The java.lang.ClassNotFoundException fails to be deserialized when
the serialization has been performed with earlier version of jdk(jdk 1.1.6)
because its serialVersionUID is not the same in different java versions.
Here is the test demonstrating the bug.
---------ClassNotFoundExceptionTest.java--------
import java.util.*;
import java.io.*;
public class ClassNotFoundExceptionTest {
public static void main(String args[]) {
ClassNotFoundException exception = new ClassNotFoundException("exception");
if (args[0].equals("write")) {
try {
FileOutputStream fos = new FileOutputStream(args[1]);
ObjectOutputStream ostream = new ObjectOutputStream(fos);
ostream.writeObject(exception);
ostream.flush();
fos.close();
System.out.println(args[1] + " is successfuly created");
} catch(IOException e) {
System.out.println("Unexpected exception : " + e);
}
} else if (args[0].equals("read")) {
try {
FileInputStream fis = new FileInputStream(args[1]);
ObjectInputStream istream = new ObjectInputStream(fis);
if (!exception.toString().equals(istream.readObject().toString())) {
System.out.println("Error");
} else {
System.out.println(args[1] + " is successfuly read");
}
} catch(Exception e) {
System.out.println("Unexpected exception : " + e);
}
}
}
}
------------The test output-----------
> jdk 1.1.6
> java ClassNotFoundExceptionTest write file
file is successfuly created
> java ClassNotFoundExceptionTest read file
file is successfuly read
> jdk 1.2
> java ClassNotFoundExceptionTest read file
Unexpected exception : java.io.InvalidClassException: java.lang.ClassNotFoundException; Local class not compatible: stream classdesc serialVersionUID=9176873029745254542 local class serialVersionUID=-8505499827617619318
======================================================================