author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
15646
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
1 |
/* |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
4 |
* |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
8 |
* |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
13 |
* accompanied this code). |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
14 |
* |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
18 |
* |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
21 |
* questions. |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
22 |
*/ |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
23 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
24 |
/* |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
25 |
* @test |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
26 |
* @bug 8007038 |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
27 |
* @summary Verify ArrayIndexOutOfBoundsException is not thrown on |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
28 |
* on calling localizedDateTime().print() with JapaneseChrono |
30820 | 29 |
* @modules java.base/sun.util.locale.provider |
15646
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
30 |
* @compile -XDignore.symbol.file Bug8007038.java |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
31 |
* @run main Bug8007038 |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
32 |
*/ |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
33 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
34 |
import java.util.*; |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
35 |
import static java.util.Calendar.*; |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
36 |
import sun.util.locale.provider.CalendarDataUtility; |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
37 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
38 |
public class Bug8007038 { |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30820
diff
changeset
|
39 |
private static final String[] calTypes = { |
15646
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
40 |
"gregory", |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
41 |
"buddhist", |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
42 |
"japanese", |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
43 |
"roc", |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
44 |
"islamic", |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
45 |
}; |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30820
diff
changeset
|
46 |
private static final int[][] eraMinMax = { |
15646
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
47 |
{GregorianCalendar.BC, GregorianCalendar.AD}, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
48 |
{0, 1}, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
49 |
{0, 4}, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
50 |
{0, 1}, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
51 |
{0, 1}, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
52 |
{0, 1}, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
53 |
}; |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30820
diff
changeset
|
54 |
private static final Locale[] testLocs = { |
15646
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
55 |
Locale.ROOT, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
56 |
Locale.forLanguageTag("ja-JP-u-ca-japanese"), |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
57 |
Locale.forLanguageTag("th-TH"), |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
58 |
Locale.forLanguageTag("th-TH-u-ca-buddhist"), |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
59 |
Locale.forLanguageTag("zh-TW-u-ca-roc"), |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
60 |
Locale.forLanguageTag("ar-EG-u-ca-islamic"), |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
61 |
Locale.forLanguageTag("xx-YY-u-ca-bogus"), |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
62 |
}; |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
63 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
64 |
public static void main(String[] args) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
65 |
for (int calIdx = 0; calIdx < calTypes.length; calIdx++) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
66 |
for (int locIdx = 0; locIdx < testLocs.length; locIdx++) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
67 |
// era |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
68 |
for (int fieldIdx = eraMinMax[calIdx][0]; fieldIdx <= eraMinMax[calIdx][1]; fieldIdx++) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
69 |
checkValueRange(calTypes[calIdx], ERA, fieldIdx, LONG, testLocs[locIdx], true); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
70 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
71 |
checkValueRange(calTypes[calIdx], ERA, eraMinMax[calIdx][0]-1, LONG, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
72 |
testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
73 |
checkValueRange(calTypes[calIdx], ERA, eraMinMax[calIdx][1]+1, |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
74 |
LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
75 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
76 |
// month |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
77 |
for (int fieldIdx = JANUARY; fieldIdx <= UNDECIMBER ; fieldIdx++) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
78 |
checkValueRange(calTypes[calIdx], MONTH, fieldIdx, LONG, testLocs[locIdx], true); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
79 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
80 |
checkValueRange(calTypes[calIdx], MONTH, JANUARY-1, LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
81 |
checkValueRange(calTypes[calIdx], MONTH, UNDECIMBER+1, LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
82 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
83 |
// day-of-week |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
84 |
for (int fieldIdx = SUNDAY; fieldIdx <= SATURDAY; fieldIdx++) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
85 |
checkValueRange(calTypes[calIdx], DAY_OF_WEEK, fieldIdx, LONG, testLocs[locIdx], true); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
86 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
87 |
checkValueRange(calTypes[calIdx], DAY_OF_WEEK, SUNDAY-1, LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
88 |
checkValueRange(calTypes[calIdx], DAY_OF_WEEK, SATURDAY+1, LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
89 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
90 |
// am/pm |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
91 |
for (int fieldIdx = AM; fieldIdx <= PM; fieldIdx++) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
92 |
checkValueRange(calTypes[calIdx], AM_PM, fieldIdx, LONG, testLocs[locIdx], true); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
93 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
94 |
checkValueRange(calTypes[calIdx], AM_PM, AM-1, LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
95 |
checkValueRange(calTypes[calIdx], AM_PM, PM+1, LONG, testLocs[locIdx], false); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
96 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
97 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
98 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
99 |
|
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
100 |
private static void checkValueRange(String calType, int field, int value, int style, Locale l, boolean isNonNull) { |
16852 | 101 |
String ret = CalendarDataUtility.retrieveJavaTimeFieldValueName(calType, field, value, style, l); |
15646
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
102 |
System.out.print("retrieveFieldValueName("+calType+", "+field+", "+value+", "+style+", "+l+")"); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
103 |
if ((ret != null) == isNonNull) { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
104 |
System.out.println(" returned "+ret); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
105 |
} else { |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
106 |
throw new RuntimeException("The call returned "+ret); |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
107 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
108 |
} |
b065aeb8e26b
8007038: ArrayIndexOutOfBoundsException on calling localizedDateTime().print() with JapaneseChrono
naoto
parents:
diff
changeset
|
109 |
} |