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