-
Bug
-
Resolution: Fixed
-
P1
-
1.1.4, 1.1.6, 1.2.0
-
1.1.6
-
generic, x86, sparc
-
generic, solaris_2.5, solaris_2.5.1, windows_nt
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2017646 | 1.2.0 | John Oconner | P1 | Resolved | Fixed | 1.2beta3 |
Name: mgC56079 Date: 10/30/97
The java.text.Collator object serialized under jdk1.1.4 fails to be
deserialized under jdk1.2 due to the incompatibility of the class on
jdk1.1.4 and jdk1.2 platforms.
Reason: the serialVersionUID field is not defined.
==== Here is the test demonstrating the bug (CollatorTest.java) ====
import java.io.*;
import java.text.*;
public class CollatorTest {
public static void main(String args[]) {
MyCollator obj;
String filepath = "RBC.ser";
if (args[0].equals("write")) {
obj = new MyCollator();
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(new FileOutputStream(filepath));
stream.writeObject(obj);
stream.close();
} catch(IOException e) {
System.out.println("Couldn't write to " + filepath + " : " + e);
System.exit(1);
}
System.out.println("written successfully");
} else if (args[0].equals("read")) {
ObjectInputStream stream = null;
try {
stream = new ObjectInputStream(new FileInputStream(filepath));
obj = (MyCollator)stream.readObject();
} catch(InvalidClassException e) {
System.out.println("Failed:" + e);
System.exit(1);
} catch(Exception e) {
System.out.println(
"Failed: couldn't read from" + filepath + " : " + e
);
System.exit(1);
}
System.out.println("Passed");
}
System.exit(0);
}
}
class MyCollator extends Collator {
public MyCollator() {}
public int hashCode() {return 0;}
public int compare(String source, String target) {return 0;}
public CollationKey getCollationKey(String source) {return null;}
}
----------The test output under jdk1.1.4-----------
#>java BigDecimalTest write
BigDecimal written successfully
#>java BigDecimalTest read
Passed
----------The test output under jdk1.2-------------
======================================================================
Name: mgC56079 Date: 10/30/97
OOPS! invalid output supplied. The correct one is:
--- jdk1.1.4 ---
% java CollatorTest write
written successfully
% java CollatorTest read
Passed
--- jdk1.2P ---
% java CollatorTest read
Failed:java.io.InvalidClassException: java.text.Collator; Local class not compatible
======================================================================
- backported by
-
JDK-2017646 java.text.Collator serialized form in jdk1.2 is not compatible with jdk1.1.4
- Resolved
- duplicates
-
JDK-4099670 java.text.Collator needs a serialVersionUID in JDK1.1.6 and JDK1.2
- Closed
-
JDK-4093559 EntryPair class does not implement Serializable
- Closed
-
JDK-4084916 serial version UID changed between 1.1 and 1.2.
- Closed