-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2
-
beta
-
generic
-
generic
Name: stC104175 Date: 04/07/2000
java version "1.2.2"
Classic VM (build 1.2.2-L, green threads, nojit)
Serialization of a Calendar instance can give problems and changing dates.
The following code snippet illustrates the problem.
The line
result.setTime(result.getTime());
does not occur in my application, but was the simplest I could find that shows
broken behaviour.
public static void main(String args[]) {
try {
Calendar c = Calendar.getInstance();
c.set(1966,0,1); // 1 jan 1966
System.out.println(c.get(c.YEAR)+" "+c.get(c.MONTH)+" "+c.get(c.DATE));
// Gives 1966 0 1
//serialize ...
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(c);
s.flush();
// deserialize ...
ObjectInputStream t = new ObjectInputStream(new
ByteArrayInputStream(out.toByteArray()));
Calendar result = (Calendar)t.readObject();
System.out.println(result.get(result.YEAR)+" "+result.get(result.MONTH)+"
"+result.get(result.DATE));
// Gives 1966 0 1
result.setTime(result.getTime());
System.out.println(result.get(result.YEAR)+" "+result.get(result.MONTH)+"
"+result.get(result.DATE));
// Gives 1965 11 19 !!!!!!!!!
}
catch (Exception e){}
}
(Review ID: 103427)
======================================================================