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

DateTimeFormatter Fails to throw an Exception on Invalid HOUR_OF_AMPM

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 13
    • core-libs
    • None
    • behavioral
    • minimal
    • Some app will start to see an exception with invalid `HOUR_OF_AMPM` input string, but that is what should be in the first place.
    • Java API
    • SE

      Summary

      Throw a DateTimeParseException on resolving an out-of-range HOUR_OF_AMPM value in `ResolverStyle.SMART mode.

      Problem

      Client code like this:

      new DateTimeFormatterBuilder()
          .appendValue(HOUR_OF_AMPM,2)
          .appendText(AMPM_OF_DAY)
          .toFormatter(US)
          .parse("12PM");

      does not throw a DateTimeParseException, even though the input hour number 12 is out of range for HOUR_OF_AMPM.

      Solution

      Throw a DateTimeParseException in such cases.

      Specification

      This is a behavioral change, thus no specification change is expected.

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

              Created:
              Updated:
              Resolved: