-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.4.0, 1.4.2
-
x86, sparc
-
solaris_7, windows_2000
Name: rmT116609 Date: 03/12/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
SunOS haggis 5.8 Generic_108528-12 sun4u sparc SUNW,Ultra-250
ADDITIONAL OPERATING SYSTEMS :
Linux tushar 2.4.16 #10 Wed Dec 19 17:11:08 EST 2001 i686 unknown
A DESCRIPTION OF THE PROBLEM :
After you set Calendar.setTimeZone() with a null timezone, any call to Calendar.setTime() throws a null pointer exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the sample code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Calendar.setTimeZone(null) should throw an exception if the Calendar class cannot handle null timezones - so that the error is trapped at the source rather than at setTime().
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:1294)
at java.util.Calendar.setTimeInMillis(Calendar.java:927)
at java.util.Calendar.setTime(Calendar.java:902)
at CalendarTZ.main(CalendarTZ.java:9)
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public class CalendarTZBug {
public static void main(String args[]) {
Calendar c = Calendar.getInstance();
c.setTimeZone(null); // Does not throw an exception
c.setTime(new Date()); // Throws a NullPointerException
}
}
---------- END SOURCE ----------
(Review ID: 144081)
======================================================================
- duplicates
-
JDK-6609695 (cal) SimpleDateFormat.setTimeZone(TimeZone) does not throw NullPointerException
- Closed
- relates to
-
JDK-6218123 (cal) API: Spec for GregorianCalendar constructors and Calendar getInstance is inconsistent.
- Resolved
-
JDK-7059113 (cal) Undocumented NullPointerException in GregorianCalendar.computeTime()
- Closed
-
JDK-8074102 DateFormat must throw a NullPointerException for setCalendar and setNumberFormat
- Closed