JDK-7059113 : (cal) Undocumented NullPointerException in GregorianCalendar.computeTime()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 6u26
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-06-24
  • Updated: 2012-03-20
  • Resolved: 2011-06-28
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The GregorianCalendar.computerTime() method <http://download.oracle.com/javase/6/docs/api/java/util/GregorianCalendar.html#computeTime()> throws a NullPointerException when the TimeZone is null. I think a failure in this case is appropriate, however just throwing a raw NPE is a bug. It should throw an IllegalStateException with a clear error message in that case. And this needs to be documented in the method Javadoc (as well as in the other API methods which call computeTime()).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample program.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
        at java.util.GregorianCalendar.computeTime(Unknown Source)
        at java.util.Calendar.updateTime(Unknown Source)
        at java.util.Calendar.getTimeInMillis(Unknown Source)
        at GregorianCalendarTest.main(GregorianCalendarTest.java:10)

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class GregorianCalendarTest {

	public static void main(String[] args) {
		GregorianCalendar cal = new GregorianCalendar();
		cal.clear();
		cal.set(2011, Calendar.JUNE, 24);
		cal.setTimeZone(null);
		cal.getTimeInMillis();
	}

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

Comments
EVALUATION Closing this CR as a duplicate of 4737887.
28-06-2011