JDK-6609380 : (cal) calling add() on a deserialized Calendar causes a NullPointerException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
  • Resolved: 2007-10-05
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)

ADDITIONAL OS VERSION INFORMATION :
MS Windowx XP 5.1.2600

A DESCRIPTION OF THE PROBLEM :
If a GregorianCalendar object is created, serialized, and then deserialized, add() no longer functions as expected.  It throws a NullPointerException one level down the call stack at getCurrentFixedDate(GregorianCalendar.java:2833).  This appears to be the same as bug report 6365360, which for some reason is marked as closed despite not being fixed (the "release fixed" appears to be an older release, in which this bug was not present - it appears to be unique to 1.5).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a GregorianCalendar object.
serialize the GregorianCalendar
deserialize the GregorianCalendar
attempt to add to it using DAY_OF_WEEK or DAY_OF_MONTH as the field (I haven't tested other fields, but I'm fairly certain MONTH doesn't cause the problem).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the date represented by the calendar should advance by one day
ACTUAL -
the call fails with NullPointerException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	java.util.GregorianCalendar.getCurrentFixedDate(GregorianCalendar.java:2833)
	java.util.GregorianCalendar.add(GregorianCalendar.java:964)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
please see bug ID 6365360 for source code to reproduce this problem.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
  Bug ID 6365360 suggests copying the calendar to a new instance.