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

Literal dash added to DateTimeFormatterBuilder causes parsing to fail

    Details

    • Subcomponent:
    • Introduced In Build:
      b112
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The following code results in an exception on Java 9, but not Java 8:

      new DateTimeFormatterBuilder()
          .append(DateTimeFormatter.BASIC_ISO_DATE)
          .appendLiteral('-')
          .append(DateTimeFormatter.ISO_LOCAL_TIME)
          .toFormatter()
          .parse("20180302-17:45:21");

      The exception is:

      Exception in thread "main" java.time.format.DateTimeParseException: Text '20180302-17:45:21' could not be parsed at index 11
          at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1988)
          at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1816)

      REGRESSION. Last worked in version 8u162

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this:

      new DateTimeFormatterBuilder()
          .append(DateTimeFormatter.BASIC_ISO_DATE)
          .appendLiteral('-')
          .append(DateTimeFormatter.ISO_LOCAL_TIME)
          .toFormatter()
          .parse("20180302-17:45:21");

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Date parses successfully
      ACTUAL -
      Exception is thrown

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.time.format.DateTimeParseException: Text '20180302-17:45:21' could not be parsed at index 11
          at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1988)
          at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1816)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.time.format.DateTimeFormatter;
      import java.time.format.DateTimeFormatterBuilder;

      public class Foo
      {
          public static void main(String[] args)
          {
              new DateTimeFormatterBuilder()
                  .append(DateTimeFormatter.BASIC_ISO_DATE)
                  .appendLiteral("-")
                  .append(DateTimeFormatter.ISO_LOCAL_TIME)
                  .toFormatter()
                  .parse("20180302-17:45:21");
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              vtheeyarath Vivek Theeyarath
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: