JDK-4651757 : API: Calendar.setTime() throws NullPointerException with a null TimeZone
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.0,1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_7,windows_2000
  • CPU: x86,sparc
  • Submitted: 2002-03-12
  • Updated: 2017-05-19
  • Resolved: 2003-10-11
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description

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) 
======================================================================

Comments
EVALUATION The API should be clarified. ###@###.### 2002-03-13 Calendar.setTimeZone() will be fixed to throw NullPointerException with null. ###@###.### 2003-09-29 This bug will not be fixed due to concerns on compatibilty problems. ###@###.### 2003-10-11
29-09-2003

WORK AROUND Use the GMT time zone if GMT+00:00 with no DST is the expected behavior. ###@###.### 2002-03-13
13-03-2002