8210142: java.util.Calendar.clone() doesn't respect sharedZone flag
Reviewed-by: rriggs
This commit is contained in:
parent
9d6230fe4e
commit
d1958eeed1
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -3326,7 +3326,9 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
|
|||||||
other.stamp[i] = stamp[i];
|
other.stamp[i] = stamp[i];
|
||||||
other.isSet[i] = isSet[i];
|
other.isSet[i] = isSet[i];
|
||||||
}
|
}
|
||||||
|
if (!sharedZone) {
|
||||||
other.zone = (TimeZone) zone.clone();
|
other.zone = (TimeZone) zone.clone();
|
||||||
|
}
|
||||||
return other;
|
return other;
|
||||||
}
|
}
|
||||||
catch (CloneNotSupportedException e) {
|
catch (CloneNotSupportedException e) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,9 +23,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4064654 4374886 4984320 4984574 4944795
|
* @bug 4064654 4374886 4984320 4984574 4944795 8210142
|
||||||
* @summary test for Calendar
|
* @summary test for Calendar
|
||||||
* @library /java/text/testlib
|
* @library /java/text/testlib
|
||||||
|
* @modules java.base/java.util:+open
|
||||||
* @run main CalendarTest
|
* @run main CalendarTest
|
||||||
* @key randomness
|
* @key randomness
|
||||||
*/
|
*/
|
||||||
@ -37,6 +38,7 @@ import java.io.IOException;
|
|||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -1176,6 +1178,29 @@ public class CalendarTest extends IntlTest {
|
|||||||
TimeZone.setDefault(savedTimeZone);
|
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
|
//eof
|
||||||
|
Loading…
x
Reference in New Issue
Block a user