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

Date "20180325" does not parse using java.text.SimpleDateFormat

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux_oracle_6.0

      Description

      FULL PRODUCT VERSION :
      NA

      ADDITIONAL OS VERSION INFORMATION :
      OE Linux - any version

      A DESCRIPTION OF THE PROBLEM :
      Hit a problem today in production with a customer that produces work in advance. Date parsing meant the system landed on a date of 20180325, when parsing this with a time the date is not valid. 24th and 26th are ok, but not 25th.

      Code below:

      String temp = '20180325 012600';
      SimpleDateFormat df = new java.text.SimpleDateFormat('yyyyMMdd HHmmss');
      df.setLenient(false);
      Date dateToSend = df.parse(temp);

      Error:
      e: <java.text.ParseException@5b1d7ab6 errorOffset=15 detailMessage=Unparseable date: "20180325 012600" cause=java.text.ParseException: Unparseable date: "20180325 012600" stackTrace=null>


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the following code:

      String temp = '20180325 012600';
      SimpleDateFormat df = new java.text.SimpleDateFormat('yyyyMMdd HHmmss');
      df.setLenient(false);
      Date dateToSend = df.parse(temp);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Date parses without error
      ACTUAL -
      Error:
      e: <java.text.ParseException@5b1d7ab6 errorOffset=15 detailMessage=Unparseable date: "20180325 012600" cause=java.text.ParseException: Unparseable date: "20180325 012600" stackTrace=null>

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Error:
      e: <java.text.ParseException@5b1d7ab6 errorOffset=15 detailMessage=Unparseable date: "20180325 012600" cause=java.text.ParseException: Unparseable date: "20180325 012600" stackTrace=null>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      String temp = '20180325 012600';
      SimpleDateFormat df = new java.text.SimpleDateFormat('yyyyMMdd HHmmss');
      df.setLenient(false);
      Date dateToSend = df.parse(temp);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Parse date and time individually.

        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: