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

DateFormat must throw a NullPointerException for setCalendar and setNumberFormat

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 9
    • 8u31
    • core-libs
    • x86
    • windows_8

      FULL PRODUCT VERSION :
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      currently DateFormat does not throw a NullPointerException when the parameter to setCalendar or setNumberFormat is null. This causes subsequent calls to the format method to fail

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Consider the following class:

      import java.text.DateFormat;
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      public class Bug {

      public static void main(String[] args) throws ParseException {
      DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
      fmt.setCalendar(null);
      fmt.setNumberFormat(null);
      fmt.format(new Date());
      }

      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect DateFormat to prevent callers from moving it into an illegal state. Both
      fmt.setCalendar(null);
      and
      fmt.setNumberFormat(null);
      must throw a NullPointerException in the code above
      ACTUAL -
      A NullPointerException is thrown at the line
      fmt.format(new Date());
      because its required internal variables were set to null

      REPRODUCIBILITY :
      This bug can be reproduced always.

            nishjain Nishit Jain
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: