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

DateFormat must throw a NullPointerException for setCalendar and setNumberFormat

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u31
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_8

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: