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

Lenient parsing makes DateTimeFormatter stricter in at least one locale

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      With lenient parsing DateTimeFormatter fails to parse strings it produces itself for a standard pattern in ksh-DE locale.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the source code (see below). Note that if you remove parseLenient() from it, then it works as expected.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      On stdout:
      d. MMM. y
      1. Jan. 1970
      {},ISO resolved to 1970-01-01

      ACTUAL -
      d. MMM. y
      1. Jan. 1970
      Exception in thread "main" java.time.format.DateTimeParseException: Text '1. Jan. 1970' could not be parsed at index 7
              at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1988)
              at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1816)
              at test.main(test.java:17)


      ---------- BEGIN SOURCE ----------
      import java.time.*;
      import java.time.chrono.*;
      import java.time.format.*;
      import java.time.temporal.*;
      import java.util.*;

      public class test
      {
          public static void main (String[] arguments) throws Exception
          {
              Locale locale = Locale.forLanguageTag ("ksh-DE");
              String pattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern (FormatStyle.MEDIUM, null, Chronology.ofLocale (locale), locale);
              DateTimeFormatter formatter = new DateTimeFormatterBuilder ().parseLenient ().appendPattern (pattern).toFormatter (locale);

              System.out.println (pattern);
              System.out.println (formatter.format (LocalDate.ofEpochDay (0)));
              System.out.println (formatter.parse (formatter.format (LocalDate.ofEpochDay (0))));
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated: