author | nishjain |
Thu, 22 Mar 2018 12:59:58 +0530 | |
changeset 49277 | cf9e3c8607b7 |
permissions | -rw-r--r-- |
49277
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
1 |
/* |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
4 |
* |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
8 |
* |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
13 |
* accompanied this code). |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
14 |
* |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
18 |
* |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
21 |
* questions. |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
22 |
*/ |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
23 |
/* |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
24 |
* @test |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
25 |
* @bug 8199672 |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
26 |
* @summary test the Formatter.format() method with java.locale.providers=SPI, |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
27 |
* COMPAT. It should not throw ClassCastException if an SPI is |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
28 |
* used and NumberFormat.getInstance() does not return a |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
29 |
* DecimalFormat object. |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
30 |
* @modules jdk.localedata |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
31 |
* @library provider |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
32 |
* @build provider/module-info provider/test.NumberFormatProviderImpl |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
33 |
* @run main/othervm -Djava.locale.providers=SPI,COMPAT FormatterWithProvider |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
34 |
*/ |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
35 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
36 |
import java.util.Formatter; |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
37 |
import java.util.Locale; |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
38 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
39 |
public class FormatterWithProvider { |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
40 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
41 |
public static void main(String[] args) { |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
42 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
43 |
Integer number = 1234567; |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
44 |
String formatString = "%,d"; |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
45 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
46 |
try { |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
47 |
testFormatter(Locale.JAPANESE, formatString, number); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
48 |
testFormatter(Locale.FRENCH, formatString, number); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
49 |
testFormatter(new Locale("hi", "IN"), formatString, number); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
50 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
51 |
} catch (ClassCastException ex) { |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
52 |
throw new RuntimeException("[FAILED: A ClassCastException is" + |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
53 |
" thrown while using Formatter.format() with VM" + |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
54 |
" argument java.locale.providers=SPI,COMPAT]", ex); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
55 |
} |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
56 |
} |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
57 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
58 |
private static void testFormatter(Locale locale, String formatString, |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
59 |
Integer number) { |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
60 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
61 |
// test using String.format |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
62 |
String.format(locale, formatString, number); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
63 |
// test using Formatter's format |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
64 |
Formatter formatter = new Formatter(locale); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
65 |
formatter.format(formatString, number); |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
66 |
} |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
67 |
|
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
68 |
} |
cf9e3c8607b7
8196399: Formatting a decimal using locale-specific grouping separators causes ArithmeticException (division by zero).
nishjain
parents:
diff
changeset
|
69 |