Name: avC70361 Date: 06/15/98
The java.sql.Time is incorrectly deserialized in jdk1.2beta4 when has been
serialized in jdk1.1.6. The instance deserialized is not equal to the instance
created for the same time, although the string representations of these
instances are the same.
Here is a test demonstrating the bug.
----------SQLTimeTest.java-------------
import java.sql.Time;
import java.io.*;
public class SQLTimeTest {
public static void main(String args[]) {
Time expected = new Time(123456789L);
if (args[0].equals("write")) {
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(new FileOutputStream(args[1]));
stream.writeObject(expected);
stream.close();
} catch(IOException e) {
System.out.println("Couldn't write to " + args[1] + " : " + e);
System.exit(1);
}
System.out.println(args[1] + " written successfully");
} else if (args[0].equals("read")) {
ObjectInputStream stream = null;
try {
stream = new ObjectInputStream(new FileInputStream(args[1]));
Time time = (Time)stream.readObject();
if (!expected.equals(time)) {
System.out.println(
"Deserialized time is not equal to expected\n" +
"deserialized time = " + time + "\n" +
"expected time = " + expected
);
System.exit(1);
}
} catch(InvalidClassException e) {
System.out.println("Failed:" + e);
System.exit(1);
} catch(Exception e) {
System.out.println(
"Failed: couldn't read from " + args[1] + " : " + e
);
System.exit(1);
}
System.out.println("Passed");
}
System.exit(0);
}
}
-----------The test output---------
Under jdk1.1.6:
<avv@stardust(pts/3).305> java -version
java version "1.1.6"
<avv@stardust(pts/3).306> java SQLTimeTest write file.ser
file.ser written successfully
<avv@stardust(pts/3).307> java SQLTimeTest read file.ser
Passed
Under jdk1.2beta4:
<avv@stardust(pts/3).309> java -version
java version "1.2beta4"
Classic VM (build JDK-1.2beta4-I, green threads, sunwjit)
<avv@stardust(pts/3).310> java SQLTimeTest read file.ser
Deserialized time is not equal to expected
deserialized time = 10:17:36
expected time = 10:17:36
======================================================================
- duplicates
-
JDK-4147483 The serializable class java.sql.Timestamp evolved incompatibly.
- Closed