Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7059113

(cal) Undocumented NullPointerException in GregorianCalendar.computeTime()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u26
    • core-libs

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

            okutsu Masayoshi Okutsu
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: