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

Incorrect 2 -> 4 year parsing and resolution in DateTimeFormatter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b113
    • Verification:
      Verified

      Description

      Parsing using the pattern "M/d/yy GGGGG" does not correctly determine the 4 digit year from the 2 digit input.
      For a ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 2576, 10, 29)
      the input of "10/29/76 B.E." is parsed as ThaiBuddhist BE 2076-10-29

      For a HijrahChronology.INSTANCE.date(HijrahEra.AH, 1425, 7, 9)
      the input "7/9/52 AH" throws an exception:


      Exception in thread "main" java.time.format.DateTimeParseException: Text '7/9/25 AH' could not be parsed: Invalid value for YearOfEra (valid values 1300 - 1600): 2025
      at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1919)
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1780)
      at bugs.StringConverter.bug2(StringConverter.java:67)
      at bugs.StringConverter.main(StringConverter.java:19)
      Caused by: java.time.DateTimeException: Invalid value for YearOfEra (valid values 1300 - 1600): 2025
      at java.time.temporal.ValueRange.checkValidIntValue(ValueRange.java:327)
      at java.time.chrono.Chronology.resolveYearOfEra(Chronology.java:1031)
      at java.time.chrono.Chronology.resolveDate(Chronology.java:975)
      at java.time.chrono.HijrahChronology.resolveDate(HijrahChronology.java:605)
      at java.time.chrono.HijrahChronology.resolveDate(HijrahChronology.java:215)
      at java.time.format.Parsed.resolveDateFields(Parsed.java:297)
      at java.time.format.Parsed.resolveFields(Parsed.java:252)
      at java.time.format.Parsed.resolve(Parsed.java:242)
      at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1954)
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1776)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rriggs Roger Riggs
                Reporter:
                rriggs Roger Riggs
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: