JDK-8352636 : SimpleDateFormat: unspecified behavior for reserved pattern letter
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.text
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 25
  • Submitted: 2025-03-21
  • Updated: 2025-06-26
  • Resolved: 2025-03-27
Related Reports
CSR :  
Description
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.


Comments
Moving to Approved.
27-03-2025