<i18n dev> RFR: JDK-8325898: ChoiceFormat returns erroneous result when formatting bad pattern [v2]

Naoto Sato naoto at openjdk.org
Thu Feb 22 18:55:54 UTC 2024


On Thu, 22 Feb 2024 17:38:50 GMT, Justin Lu <jlu at openjdk.org> wrote:

>> src/java.base/share/classes/java/text/ChoiceFormat.java line 332:
>> 
>>> 330: 
>>> 331:     // Used to explicitly define the segment mode while applying a pattern
>>> 332:     private enum Segment {
>> 
>> Do we need a new enum? Would introducing a new enum solve something that cannot be done with the existing implementation?
>
> No, we don't _need_ a new enum, although I prefer it for readability.
> 
> For example, I think the following is more clear:
> - `Segment.LIMIT.bldr.toString()`over `segments[1].toString();`.
> - `seg = Segment.LIMIT;` over `part = 0;`
> 
> Can also no longer do something such as `part = 2;` even if unlikely.
> 
> Although I can see the argument of not wanting an enum as `part` is either only `0` or `1`. Either is OK with me.

OK, now the new enum can be shared with multiple threads with this implementation, but I guess it is OK as ChoiceFormat does not guarantee synchronization.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17883#discussion_r1499732561


More information about the i18n-dev mailing list