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

SimpleDateFormatter("yyyy-MM-dd'T'HH:mm:ss'Z'") parses malformed dates

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      A DESCRIPTION OF THE PROBLEM :
      Using SimpleDateFormatter("yyyy-MM-dd'T'HH:mm:ss'Z'").parse() on a date of "2018-11-330T13:22:36Z" is not only accepted but when decoded to a UTC date becomes "Thu Sep 26 13:22:36 EDT 2019".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.text.ParseException;
      import java.text.SimpleDateFormat;

      public class foo {
          public static void main(String[] args) {
      String badDate = "2018-11-330T13:22:36Z";
      SimpleDateFormat format = new SimpleDateFormat(
      "yyyy-MM-dd'T'HH:mm:ss'Z'");
      try {
      System.out.println(format.parse(badDate));
      } catch (ParseException ex) {
      ex.printStackTrace();
      }
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect a ParseException to be thrown when the String badDate didn't match the format.
      ACTUAL -
      Thu Sep 26 13:22:36 EDT 2019 was returned. It appears Java seems to be adding the extra days onto the date.

      ---------- BEGIN SOURCE ----------
      import java.text.ParseException;
      import java.text.SimpleDateFormat;

      public class foo {
          public static void main(String[] args) {
      String badDate = "2018-11-330T13:22:36Z";
      SimpleDateFormat format = new SimpleDateFormat(
      "yyyy-MM-dd'T'HH:mm:ss'Z'");
      try {
      System.out.println(format.parse(badDate));
      } catch (ParseException ex) {
      ex.printStackTrace();
      }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Using regex to match the digit characters and then parse the date.

      FREQUENCY : always


        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: