< prev index next >

test/jdk/java/util/Calendar/CalendarTest.java

Print this page
rev 51631 : [mq]: 8210142

*** 1,7 **** /* ! * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,33 **** * questions. */ /** * @test ! * @bug 4064654 4374886 4984320 4984574 4944795 * @summary test for Calendar * @library /java/text/testlib * @run main CalendarTest * @key randomness */ import java.io.File; --- 21,34 ---- * questions. */ /** * @test ! * @bug 4064654 4374886 4984320 4984574 4944795 8210142 * @summary test for Calendar * @library /java/text/testlib + * @modules java.base/java.util:+open * @run main CalendarTest * @key randomness */ import java.io.File;
*** 35,44 **** --- 36,46 ---- import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; + import java.lang.reflect.Field; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.SimpleTimeZone;
*** 1174,1181 **** --- 1176,1206 ---- } finally { Locale.setDefault(savedLocale); TimeZone.setDefault(savedTimeZone); } } + + public void TestClonedSharedZones() throws NoSuchFieldException, IllegalAccessException { + Field zone = Calendar.class.getDeclaredField("zone"); + zone.setAccessible(true); + Field sharedZone = Calendar.class.getDeclaredField("sharedZone"); + sharedZone.setAccessible(true); + + // create a new calendar with any date, and clone it. + Calendar c1 = new GregorianCalendar(); + Calendar c2 = (Calendar) c1.clone(); + + // c1 should have a shared zone + if (!sharedZone.getBoolean(c1)) { + errln("Failed : c1.sharedZone == false"); + } else { + // c2 should have a shared zone too + if (!sharedZone.getBoolean(c2)) { + errln("Failed : c2.sharedZone == false"); + } else if (zone.get(c1) != zone.get(c2)) { + errln("Failed : c1.zone != c2.zone"); + } + } + } } //eof
< prev index next >