6609718: [Fmt-Ch] uninformative exception in ChoiceFormat.applyPattern(String)
authornishjain
Tue, 22 Aug 2017 12:04:53 +0530
changeset 46893 4c5a4cd5b092
parent 46892 fd5023dd3c85
child 46894 8e950730d2c8
child 47013 5ae11f15e343
6609718: [Fmt-Ch] uninformative exception in ChoiceFormat.applyPattern(String) Reviewed-by: naoto Contributed-by: nishit.jain@oracle.com
jdk/src/java.base/share/classes/java/text/ChoiceFormat.java
--- 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;