JDK-6365360 : REGRESSION: JRE1.5.0_06: deserialized GregorianCalender throws NPE
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2005-12-20
  • Updated: 2011-02-16
  • Resolved: 2005-12-21
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux darkstar 2.6.8-24.18-smp #1 SMP Fri Aug 19 11:56:28 UTC 2005 i686 i686 i386 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When a GregorianCalendar is serialized and deserialized, the calendar can't be manipulated any more, e.g. the add(int, int) method fails with a NullPointerException.

This is a regression. In JRE1.5.0_05 and earlier the bug is not present.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile GregorianCalendarBug.java
2. Run the program

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception occurs.
ACTUAL -
A NullPointerException occurs.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
        at java.util.GregorianCalendar.getCurrentFixedDate(GregorianCalendar.java:2833)
        at java.util.GregorianCalendar.add(GregorianCalendar.java:964)
        at GregorianCalendarBug.main(GregorianCalendarBug.java:18)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;

public class GregorianCalendarBug {

	public static void main(String[] args) throws Exception {
		Calendar cal = new GregorianCalendar(Locale.US);
		ObjectOutputStream os = new ObjectOutputStream(new
FileOutputStream("calendar.bin"));
		cal.set(Calendar.YEAR, 2005);
		cal.set(Calendar.MONTH, 12);
		cal.set(Calendar.DATE, 1);
		os.writeObject(cal);
		os.close();
		ObjectInputStream is = new ObjectInputStream(new
FileInputStream("calendar.bin"));
		cal = (Calendar) is.readObject();
		cal.add(Calendar.DATE, 10);
	}

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
A rought workaround is to create a new GregorianCalender and set the time from the old one.

Release Regression From : 5.0u5
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Comments
EVALUATION The fix went to 5.0u7 b01. See also 6263644.
02-03-2006