On Mon, 8 Jun 2026 20:55:00 GMT, Justin Lu <[email protected]> wrote:

> ListFormat validates patterns before passing them to MessageFormat, but it 
> currently allows single quotes as is. MessageFormat interprets these as 
> escaping syntax, which can lead to incorrect output. For example, given the 
> end pattern  `"{0}'{1}'"` and an empty two pattern, a `ListFormat` formats 
> `List.of("foo", "bar")` as `"foo{1}"` instead of `"foo'bar'"`.
> 
> This behavior violates the specification, as ListFormat does not define any 
> escaping mechanisms. This PR converts ListFormat patterns to the 
> corresponding MessageFormat pattern by ensuring all single quotes are 
> doubled, such that they are always treated literally by the MessageFormat. I 
> intentionally handle the replacement logic at the MessageFormat creation site 
> instead of the existing ListFormat validation, because the patterns should 
> remain exactly the same as the input given by the user.
> 
> I am treating this as a normal bug fix since the current behavior violates 
> the specification and is incorrect. No one should be relying on this type of 
> behavior. However, I can file a CSR if deemed necessary.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

This pull request has now been integrated.

Changeset: 7f62474f
Author:    Justin Lu <[email protected]>
URL:       
https://git.openjdk.org/jdk/commit/7f62474fcb63392c61239c0a54ddea70002832ac
Stats:     36 lines in 2 files changed: 29 ins; 0 del; 7 mod

8386200: ListFormat incorrectly escapes single quotes

Reviewed-by: naoto

-------------

PR: https://git.openjdk.org/jdk/pull/31430

Reply via email to