-
Bug
-
Resolution: Fixed
-
P3
-
1.1.4, 1.1.5, 1.2.0
-
1.2beta3
-
generic, x86, sparc
-
generic, solaris_2.5, windows_nt
-
Verified
Name: avC70361 Date: 12/04/97
java.util.TimeZone instances for some time zone Ids (GMT, MET, IST etc.) are
incorrectly serialized or deserialized: the instances before and after
serialization are not equal. This is caused by a fact that during the
deserialization process in method java.util.SimpleTimeZone.readObject(
ObjectInputStream) after reading object's fields the startDayOfWeek and
endDayOfWeek fields are set to Calendar.SUNDAY value if they have been equal to
0. But when initializing TimeZone instance with constructor TimeZone(int,
String) these fields are set to default value 0.
Here is the test demonstrating the bug:
----------TimeZoneTest.java---------
import java.util.TimeZone;
import java.io.*;
public class TimeZoneTest {
public static void main(String[] args) {
TimeZone zone = TimeZone.getTimeZone(args[0]);
try {
ByteArrayOutputStream baos;
ObjectOutputStream ostream = new ObjectOutputStream(baos = new ByteArrayOutputStream());
ostream.writeObject(zone);
ostream.close();
baos.close();
ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
if (!zone.equals(istream.readObject())) {
System.out.println("Time zone " + args[0] + " are not equal to serialized/deserialized one.");
}
} catch(Exception e) {
System.out.println(e);
}
}
}
---------The test outputs-----------
#>java TimeZoneTest GMT
Time zone GMT are not equal to serialized/deserialized one.
#>java TimeZoneTest MET
Time zone MET are not equal to serialized/deserialized one.
#>java TimeZoneTest IST
Time zone IST are not equal to serialized/deserialized one.
------------------------------------
======================================================================
- duplicates
-
JDK-4075089 SimpleDateFormat parse method does not work
- Closed