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

java.text.SimpleDateFormat fails to parse 3 letter month 'Sep'

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      I have no reason to think this is in any way platform specific, but my system is:
      java.version = 16.0.2
      javafx.runtime.version = 16+8
      os.name = Windows 10
      os.arch = amd64
      os.version = 10.0

      A DESCRIPTION OF THE PROBLEM :
      Until JDK 15, SimpleDateFormat would successfully parse date strings including the month September abbreviated as the 3 letters "Sep".
      With JDK 16, this now fails with java.text.ParseException: Unparseable dateIt will parse 
      September abbreviated as the 4 letters "Sept", but if the date string comes from third party software, for example the "expires" value in the header data for a cookie from a web browser, JDK 16 now fails where JDK 15 worked.
      I have confirmed that this is still broken in JDK 17 & 18 early access versions.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to parse a date such as "Sat, 03 Sep 2022 15:42:22 GMT" using SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss")

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      java.version = 15
      dateString = Sat, 03 Jan 2022 15:42:22 GMT
          date = Mon Jan 03 15:42:22 GMT 2022
          formatted date = Mon, 03 Jan 2022 15:42:22
      dateString = Sat, 03 Feb 2022 15:42:22 GMT
          date = Thu Feb 03 15:42:22 GMT 2022
          formatted date = Thu, 03 Feb 2022 15:42:22
      dateString = Sat, 03 Mar 2022 15:42:22 GMT
          date = Thu Mar 03 15:42:22 GMT 2022
          formatted date = Thu, 03 Mar 2022 15:42:22
      dateString = Sat, 03 Apr 2022 15:42:22 GMT
          date = Sun Apr 03 15:42:22 BST 2022
          formatted date = Sun, 03 Apr 2022 15:42:22
      dateString = Sat, 03 May 2022 15:42:22 GMT
          date = Tue May 03 15:42:22 BST 2022
          formatted date = Tue, 03 May 2022 15:42:22
      dateString = Sat, 03 Jun 2022 15:42:22 GMT
          date = Fri Jun 03 15:42:22 BST 2022
          formatted date = Fri, 03 Jun 2022 15:42:22
      dateString = Sat, 03 Jul 2022 15:42:22 GMT
          date = Sun Jul 03 15:42:22 BST 2022
          formatted date = Sun, 03 Jul 2022 15:42:22
      dateString = Sat, 03 Aug 2022 15:42:22 GMT
          date = Wed Aug 03 15:42:22 BST 2022
          formatted date = Wed, 03 Aug 2022 15:42:22
      dateString = Sat, 03 Sep 2022 15:42:22 GMT
          date = Sat Sep 03 15:42:22 BST 2022
          formatted date = Sat, 03 Sep 2022 15:42:22
      dateString = Sat, 03 Oct 2022 15:42:22 GMT
          date = Mon Oct 03 15:42:22 BST 2022
          formatted date = Mon, 03 Oct 2022 15:42:22
      dateString = Sat, 03 Nov 2022 15:42:22 GMT
          date = Thu Nov 03 15:42:22 GMT 2022
          formatted date = Thu, 03 Nov 2022 15:42:22
      dateString = Sat, 03 Dec 2022 15:42:22 GMT
          date = Sat Dec 03 15:42:22 GMT 2022
          formatted date = Sat, 03 Dec 2022 15:42:22
      dateString = Sat, 03 Sept 2022 15:42:22 GMT
          java.text.ParseException: Unparseable date: "Sat, 03 Sept 2022 15:42:22 GMT"
      ACTUAL -
      java.version = 16.0.2
      dateString = Sat, 03 Jan 2022 15:42:22 GMT
          date = Mon Jan 03 15:42:22 GMT 2022
          formatted date = Mon, 03 Jan 2022 15:42:22
      dateString = Sat, 03 Feb 2022 15:42:22 GMT
          date = Thu Feb 03 15:42:22 GMT 2022
          formatted date = Thu, 03 Feb 2022 15:42:22
      dateString = Sat, 03 Mar 2022 15:42:22 GMT
          date = Thu Mar 03 15:42:22 GMT 2022
          formatted date = Thu, 03 Mar 2022 15:42:22
      dateString = Sat, 03 Apr 2022 15:42:22 GMT
          date = Sun Apr 03 15:42:22 BST 2022
          formatted date = Sun, 03 Apr 2022 15:42:22
      dateString = Sat, 03 May 2022 15:42:22 GMT
          date = Tue May 03 15:42:22 BST 2022
          formatted date = Tue, 03 May 2022 15:42:22
      dateString = Sat, 03 Jun 2022 15:42:22 GMT
          date = Fri Jun 03 15:42:22 BST 2022
          formatted date = Fri, 03 Jun 2022 15:42:22
      dateString = Sat, 03 Jul 2022 15:42:22 GMT
          date = Sun Jul 03 15:42:22 BST 2022
          formatted date = Sun, 03 Jul 2022 15:42:22
      dateString = Sat, 03 Aug 2022 15:42:22 GMT
          date = Wed Aug 03 15:42:22 BST 2022
          formatted date = Wed, 03 Aug 2022 15:42:22
      dateString = Sat, 03 Sep 2022 15:42:22 GMT
          java.text.ParseException: Unparseable date: "Sat, 03 Sep 2022 15:42:22 GMT"
      dateString = Sat, 03 Oct 2022 15:42:22 GMT
          date = Mon Oct 03 15:42:22 BST 2022
          formatted date = Mon, 03 Oct 2022 15:42:22
      dateString = Sat, 03 Nov 2022 15:42:22 GMT
          date = Thu Nov 03 15:42:22 GMT 2022
          formatted date = Thu, 03 Nov 2022 15:42:22
      dateString = Sat, 03 Dec 2022 15:42:22 GMT
          date = Sat Dec 03 15:42:22 GMT 2022
          formatted date = Sat, 03 Dec 2022 15:42:22
      dateString = Sat, 03 Sept 2022 15:42:22 GMT
          date = Sat Sep 03 15:42:22 BST 2022
          formatted date = Sat, 03 Sept 2022 15:42:22

      Full stack trace:
      java.text.ParseException: Unparseable date: "Sat, 03 Sep 2022 15:42:22 GMT"
      at java.base/java.text.DateFormat.parse(DateFormat.java:396)
      at dateparsingbug.DateParsingBug.main(DateParsingBug.java:38)

      ---------- BEGIN SOURCE ----------

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

      public class DateParsingBug {

      /**
      * @param args the command line arguments
      */
      public static void main(String[] args) {
      SimpleDateFormat TEST_DATE_AND_TIME_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
      String[] monthNames = {
      "Jan",
      "Feb",
      "Mar",
      "Apr",
      "May",
      "Jun",
      "Jul",
      "Aug",
      "Sep",
      "Oct",
      "Nov",
      "Dec",
      "Sept"
      };

      System.out.println("java.version = " + System.getProperty("java.version"));
      for (String monthName: monthNames) {
      try {
      String dateString = "Sat, 03 " + monthName + " 2022 15:42:22 GMT";
      System.out.println("dateString = " + dateString);
      Date date = TEST_DATE_AND_TIME_FORMAT.parse(dateString);
      System.out.println(" date = " + date);
      System.out.println(" formatted date = " + TEST_DATE_AND_TIME_FORMAT.format(date));
      } catch (Exception ex) {
      System.out.println(" " + ex);
      }
      }
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            naoto Naoto Sato
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: