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

DateTimeFormatter throws DateTimeParseException on valid input

XMLWordPrintable

    • b19
    • 11
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.17134.320]

      openjdk version "11" 2018-09-25
      OpenJDK Runtime Environment 18.9 (build 11+28)
      OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

      openjdk version "12-ea" 2019-03-19
      OpenJDK Runtime Environment 19.3 (build 12-ea+13)
      OpenJDK 64-Bit Server VM 19.3 (build 12-ea+13, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Running the attached testcase under Java 10.0.2 works. Running the same testcase under Java 11 or Java 12 throws a DateTimeParseException.

      REGRESSION : Last worked in version 10.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run testcase

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Result: 2018-09-29T20:49:02Z
      ACTUAL -
      Exception in thread "main" java.time.format.DateTimeParseException: Text 'Sat, 29 Sep 2018 20:49:02 GMT' could not be parsed at index 0
              at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
              at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
              at Testcase.main(Testcase.java:14)

      ---------- BEGIN SOURCE ----------
      import java.time.Instant;
      import java.time.format.DateTimeFormatter;
      import java.time.format.DateTimeFormatterBuilder;
      import java.time.format.DateTimeFormatterBuilder;
      import java.util.Locale;

      class Testcase
      {
      public static void main (String[] args) throws java.lang.Exception
      {
      DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().
      appendPattern("EEE, dd MMM yyyy HH:mm:ss zzz").
      toFormatter(Locale.CANADA);
      Instant result = dateFormatter.parse("Sat, 29 Sep 2018 20:49:02 GMT", Instant::from);
      System.out.println("Result: " + result);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use Locale.US instead of Locale.CANADA

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: