RFR: JDK-6285888: ChoiceFormat can support unescaped relational symbols in the Format segment

Justin Lu jlu at openjdk.org
Tue Jan 30 21:23:56 UTC 2024


Please review this PR and [CSR](https://bugs.openjdk.org/browse/JDK-8314822) which allows for the _Format_ segment of a ChoiceFormat pattern to use the ChoiceFormat Relational symbols without the need to escape them using quotes. Previously, using a non escaped Relational symbol within a _Format_ segment would throw an IAE.

Implementation wise, this can be achieved by adding an additional check of `part == 0` to the relational symbol conditional. This is safe to do, as any subsequent relational symbols should only come after a '|' is parsed, which sets part back to 0. This ensures that for the duration of `part = 1` (Format segment), the relational symbols can be used without syntactic meaning.

For example, this change allows behavior such as: `new ChoiceFormat("1#The code is #7281")`. Previously, the workaround would have been new `ChoiceFormat("1#The code is '#'7281")` to achieve the same formatted behavior. Please see the CSR for more detail.

Additionally, this change also includes an unrelated grouping of the ChoiceFormat examples under a single header: **Usage Information**.

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

Commit messages:
 - update PatternsTest
 - more accurately define the SubPattern note
 - init

Changes: https://git.openjdk.org/jdk/pull/17640/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17640&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-6285888
  Stats: 210 lines in 3 files changed: 144 ins; 59 del; 7 mod
  Patch: https://git.openjdk.org/jdk/pull/17640.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17640/head:pull/17640

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


More information about the core-libs-dev mailing list