6609718: [Fmt-Ch] uninformative exception in ChoiceFormat.applyPattern(String)
Reviewed-by: naoto
Contributed-by: nishit.jain@oracle.com
--- a/jdk/src/java.base/share/classes/java/text/ChoiceFormat.java Tue Aug 22 07:52:40 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/text/ChoiceFormat.java Tue Aug 22 12:04:53 2017 +0530
@@ -202,26 +202,26 @@
segments[part].append(ch);
} else if (ch == '<' || ch == '#' || ch == '\u2264') {
if (segments[0].length() == 0) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Each interval must"
+ + " contain a number before a format");
}
- try {
- String tempBuffer = segments[0].toString();
- if (tempBuffer.equals("\u221E")) {
- startValue = Double.POSITIVE_INFINITY;
- } else if (tempBuffer.equals("-\u221E")) {
- startValue = Double.NEGATIVE_INFINITY;
- } else {
- startValue = Double.valueOf(segments[0].toString()).doubleValue();
- }
- } catch (Exception e) {
- throw new IllegalArgumentException();
+
+ String tempBuffer = segments[0].toString();
+ if (tempBuffer.equals("\u221E")) {
+ startValue = Double.POSITIVE_INFINITY;
+ } else if (tempBuffer.equals("-\u221E")) {
+ startValue = Double.NEGATIVE_INFINITY;
+ } else {
+ startValue = Double.valueOf(tempBuffer);
}
+
if (ch == '<' && startValue != Double.POSITIVE_INFINITY &&
startValue != Double.NEGATIVE_INFINITY) {
startValue = nextDouble(startValue);
}
if (startValue <= oldStartValue) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Incorrect order of"
+ + " intervals, must be in ascending order");
}
segments[0].setLength(0);
part = 1;