Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/util/Calendar/Bug8007038.java
48795 views
/*1* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 800703826* @summary Verify ArrayIndexOutOfBoundsException is not thrown on27* on calling localizedDateTime().print() with JapaneseChrono28* @compile -XDignore.symbol.file Bug8007038.java29* @run main Bug800703830*/3132import java.util.*;33import static java.util.Calendar.*;34import sun.util.locale.provider.CalendarDataUtility;3536public class Bug8007038 {37private final static String[] calTypes = {38"gregory",39"buddhist",40"japanese",41"roc",42"islamic",43};44private final static int[][] eraMinMax = {45{GregorianCalendar.BC, GregorianCalendar.AD},46{0, 1},47{0, 5},48{0, 1},49{0, 1},50{0, 1},51};52private final static Locale[] testLocs = {53Locale.ROOT,54Locale.forLanguageTag("ja-JP-u-ca-japanese"),55Locale.forLanguageTag("th-TH"),56Locale.forLanguageTag("th-TH-u-ca-buddhist"),57Locale.forLanguageTag("zh-TW-u-ca-roc"),58Locale.forLanguageTag("ar-EG-u-ca-islamic"),59Locale.forLanguageTag("xx-YY-u-ca-bogus"),60};6162public static void main(String[] args) {63for (int calIdx = 0; calIdx < calTypes.length; calIdx++) {64for (int locIdx = 0; locIdx < testLocs.length; locIdx++) {65// era66for (int fieldIdx = eraMinMax[calIdx][0]; fieldIdx <= eraMinMax[calIdx][1]; fieldIdx++) {67checkValueRange(calTypes[calIdx], ERA, fieldIdx, LONG, testLocs[locIdx], true);68}69checkValueRange(calTypes[calIdx], ERA, eraMinMax[calIdx][0]-1, LONG,70testLocs[locIdx], false);71checkValueRange(calTypes[calIdx], ERA, eraMinMax[calIdx][1]+1,72LONG, testLocs[locIdx], false);7374// month75for (int fieldIdx = JANUARY; fieldIdx <= UNDECIMBER ; fieldIdx++) {76checkValueRange(calTypes[calIdx], MONTH, fieldIdx, LONG, testLocs[locIdx], true);77}78checkValueRange(calTypes[calIdx], MONTH, JANUARY-1, LONG, testLocs[locIdx], false);79checkValueRange(calTypes[calIdx], MONTH, UNDECIMBER+1, LONG, testLocs[locIdx], false);8081// day-of-week82for (int fieldIdx = SUNDAY; fieldIdx <= SATURDAY; fieldIdx++) {83checkValueRange(calTypes[calIdx], DAY_OF_WEEK, fieldIdx, LONG, testLocs[locIdx], true);84}85checkValueRange(calTypes[calIdx], DAY_OF_WEEK, SUNDAY-1, LONG, testLocs[locIdx], false);86checkValueRange(calTypes[calIdx], DAY_OF_WEEK, SATURDAY+1, LONG, testLocs[locIdx], false);8788// am/pm89for (int fieldIdx = AM; fieldIdx <= PM; fieldIdx++) {90checkValueRange(calTypes[calIdx], AM_PM, fieldIdx, LONG, testLocs[locIdx], true);91}92checkValueRange(calTypes[calIdx], AM_PM, AM-1, LONG, testLocs[locIdx], false);93checkValueRange(calTypes[calIdx], AM_PM, PM+1, LONG, testLocs[locIdx], false);94}95}96}9798private static void checkValueRange(String calType, int field, int value, int style, Locale l, boolean isNonNull) {99String ret = CalendarDataUtility.retrieveJavaTimeFieldValueName(calType, field, value, style, l);100System.out.print("retrieveFieldValueName("+calType+", "+field+", "+value+", "+style+", "+l+")");101if ((ret != null) == isNonNull) {102System.out.println(" returned "+ret);103} else {104throw new RuntimeException("The call returned "+ret);105}106}107}108109110