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

SimpleDateFormat: unspecified behavior for reserved pattern letter

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • low
    • Low chance that an implementation defined some behavior for reserved characters other than throwing an exception. In that case, the implementation would be made non-compliant with this change.
    • Java API
    • SE

      Summary

      Clarify the specification for java.text.SimpleDateFormat patterns regarding reserved letters.

      Problem

      The SimpleDateFormat specification defines certain pattern letters as 'reserved'. However, it is not explicitly defined what the behavior is, when these letters are used in a pattern. (Although it is reasonable to infer.) Thus, behavior regarding reserved characters can be interpreted as being deferred to implementers. For example, ignoring those characters, or copying them into output instead of throwing an exception.

      Solution

      Explicitly state that an IllegalArgumentException is thrown, if a reserved character is used in a pattern. This long standing JDK reference implementation behavior should be made normative to all implementations.

      Specification

      Amend the wording above the patterns table,

        * The following pattern letters are defined (all other characters from
        * {@code 'A'} to {@code 'Z'} and from {@code 'a'} to
      - * {@code 'z'} are reserved):
      + * {@code 'z'} not in the table below are reserved). {@link #applyPattern(String)},
      + * {@link #applyLocalizedPattern(String)}, and the {@link #SimpleDateFormat(String)
      + * SimpleDateFormat constructors} throw {@code IllegalArgumentException} when
      + * passed a pattern containing an unquoted reserved character.

            jlu Justin Lu
            duke J. Duke
            Naoto Sato, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: