JDK-6609695 : (cal) SimpleDateFormat.setTimeZone(TimeZone) does not throw NullPointerException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
  • Resolved: 2007-10-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.4.x

ADDITIONAL OS VERSION INFORMATION :
win2ksp4

A DESCRIPTION OF THE PROBLEM :
SimpleDateFormat.setTimeZone(TimeZone) (or perhaps some base class) does not throw a NPE if a null is passed in.

This may create difficult to trace / ambiguous NPEs at a later time, such as in the exmaple of calling DateFormat.format():

java.lang.NullPointerException
	at java.util.GregorianCalendar.computeFieldsImpl(GregorianCalendar.java:1321)
	at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:1298)
	at java.util.Calendar.setTimeInMillis(Calendar.java:927)
	at java.util.Calendar.setTime(Calendar.java:902)
	at java.text.SimpleDateFormat.format(SimpleDateFormat.java:782)
	at java.text.SimpleDateFormat.format(SimpleDateFormat.java:775)
	at java.text.DateFormat.format(DateFormat.java:314)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Pass a null to SimpleDateFormat.setTimeZone; no Exception is thrown.


REPRODUCIBILITY :
This bug can be reproduced always.