Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Calendar/bug4401223.java
47182 views
/*1* Copyright (c) 2001, 2016, 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 440122326* @summary Make sure that GregorianCalendar doesn't cause IllegalArgumentException at some special situations which are related to the Leap Year.27* @library /java/text/testlib28*/2930import java.util.*;3132public class bug4401223 extends IntlTest {3334public void Test4401223a() {35int status = 0;36String s = null;3738try {39Date date = new Date(2000-1900, Calendar.FEBRUARY, 29);40GregorianCalendar gc = new GregorianCalendar();41gc.setTime(date);42gc.setLenient(false);43gc.set(Calendar.YEAR, 2001);44s = "02/29/00 & set(YEAR,2001) = " + gc.getTime().toString();45} catch (Exception ex) {46status++;47s = "Exception occurred for 2/29/00 & set(YEAR,2001): " + ex;48}49if (status > 0) {50errln(s);51} else {52logln(s);53}54}5556public void Test4401223b() {57int status = 0;58String s = null;5960try {61Date date = new Date(2000-1900, Calendar.DECEMBER, 31);62GregorianCalendar gc = new GregorianCalendar();63gc.setTime(date);64gc.setLenient(false);65gc.set(Calendar.YEAR, 2001);6667if (gc.get(Calendar.YEAR) != 2001 ||68gc.get(Calendar.MONTH) != Calendar.DECEMBER ||69gc.get(Calendar.DATE) != 31 ||70gc.get(Calendar.DAY_OF_YEAR) != 365) {71status++;72s = "Wrong Date : 12/31/00 & set(YEAR,2001) ---> " + gc.getTime().toString();73} else {74s = "12/31/00 & set(YEAR,2001) = " + gc.getTime().toString();75}76} catch (Exception ex) {77status++;78s = "Exception occurred for 12/31/00 & set(YEAR,2001) : " + ex;79}80if (status > 0) {81errln(s);82} else {83logln(s);84}85}8687public static void main(String[] args) throws Exception {88new bug4401223().run(args);89}90}919293