-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
6u26
-
x86
-
windows_7
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 ----------
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 ----------
- duplicates
-
JDK-4737887 (cal) API: Calendar methods taking field should document exceptions
- Resolved
- relates to
-
JDK-4651757 API: Calendar.setTime() throws NullPointerException with a null TimeZone
- Closed