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

API: Calendar.setTime() throws NullPointerException with a null TimeZone

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.0, 1.4.2
    • core-libs
    • x86, sparc
    • solaris_7, windows_2000



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

            okutsu Masayoshi Okutsu
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: