Skip to content

Commit b665fe3

Browse files
author
Justin Lu
committed
6801704: ChoiceFormat::applyPattern inconsistency for invalid patterns
Reviewed-by: naoto
1 parent a7280d1 commit b665fe3

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/java.base/share/classes/java/text/ChoiceFormat.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@
134134
* Use two single quotes in a row to produce a literal single quote. For example,
135135
* {@code new ChoiceFormat("1# ''one'' ").format(1)} returns {@code " 'one' "}.
136136
*
137+
* @apiNote A subclass could perform more consistent pattern validation by
138+
* throwing an {@code IllegalArgumentException} for all incorrect cases.
139+
* @implNote Given an incorrect pattern, this implementation may either
140+
* throw an exception or succeed and discard the incorrect portion. A {@code
141+
* NumberFormatException} is thrown if a {@code limit} can not be
142+
* parsed as a numeric value and an {@code IllegalArgumentException} is thrown
143+
* if a {@code SubPattern} is missing, or the intervals are not ascending.
144+
* Discarding the incorrect portion may result in a ChoiceFormat with
145+
* empty {@code limits} and {@code formats}.
146+
*
137147
* <h2>Usage Information</h2>
138148
*
139149
* <p>
@@ -227,11 +237,12 @@ public class ChoiceFormat extends NumberFormat {
227237
private static final long serialVersionUID = 1795184449645032964L;
228238

229239
/**
230-
* Apply the given pattern to this ChoiceFormat object. The syntax
231-
* for the ChoiceFormat pattern can be seen in the {@linkplain ##patterns
232-
* Patterns} section. Unlike {@link #setChoices(double[], String[])} this
233-
* method will throw an {@code IllegalArgumentException} if the {@code
234-
* limits} are not in ascending order.
240+
* Apply the given pattern to this ChoiceFormat object. The syntax and error
241+
* related caveats for the ChoiceFormat pattern can be found in the
242+
* {@linkplain ##patterns Patterns} section. Unlike {@link #setChoices(double[],
243+
* String[])}, this method will throw an {@code IllegalArgumentException} if
244+
* the {@code limits} are not in ascending order.
245+
*
235246
* @param newPattern a pattern string
236247
* @throws NullPointerException if {@code newPattern}
237248
* is {@code null}
@@ -399,9 +410,11 @@ public String toPattern() {
399410

400411
/**
401412
* Constructs a ChoiceFormat with limits and corresponding formats
402-
* based on the pattern.
403-
* The syntax for the ChoiceFormat pattern can be seen in the {@linkplain
404-
* ##patterns Patterns} section.
413+
* based on the pattern. The syntax and error related caveats for the
414+
* ChoiceFormat pattern can be found in the {@linkplain ##patterns Patterns}
415+
* section. Unlike {@link #ChoiceFormat(double[], String[])}, this constructor will
416+
* throw an {@code IllegalArgumentException} if the {@code limits} are not
417+
* in ascending order.
405418
*
406419
* @param newPattern the new pattern string
407420
* @throws NullPointerException if {@code newPattern} is

0 commit comments

Comments
 (0)