On Thu, 4 Jun 2026 17:53:52 GMT, Justin Lu <[email protected]> wrote:

>> Naoto Sato has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   test mod
>
> src/java.base/share/classes/java/text/ListFormat.java line 687:
> 
>> 685:         var positions = new int[3];
>> 686:         for (int i = 0; i < positions.length; i++) {
>> 687:             var ph = "{" + i + "}";
> 
> `ListFormat` uses `MessageFormat`, which means that any patterns taken by the 
> former get passed to the latter.
> 
> What would we expect to happen if `{3}` was passed as a pattern. Do we expect 
> that to be printed out literally? Do we expect to reject it because it takes 
> the form of a placeholder but exceeds the `0-2` value range?
> 
> In the current form, depending on the number of elements, it could either be 
> printed out literally, or it could be interpreted as a `MessageFormat` 
> pattern. For example,
> 
> 
> String[] p = {
>       "{3} {0}, {1}",
>       "{0}, {1}",
>       "{0}, and {1}",
>       "",
>       "" 
> };
> var lf = ListFormat.getInstance(p);
> lf.format(List.of("a", "b", "c", "d")); // -> d a, b, c, and d
> lf.format(List.of("a", "b", "c")); // -> {3} a, b, and c
> 
> 
> I would not be opposed to rejecting any placeholders that are not in the form 
> of only 0, 1, and 2. I am going to guess that no locales rely on 
> {HARD_CODED_NUMBER} as being a part of their list patterns. What do you think?

Good point. I think rejecting is fine. In fact, I made it stricter as any curly 
brace use other than 0/1/2 now throws an exception because MessageFormat has 
its own parsing, which prevents "{foo}" from working as a literal.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31377#discussion_r3359553245

Reply via email to