summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--luni/src/main/java/java/text/SimpleDateFormat.java6
-rw-r--r--luni/src/test/java/java/text/AllTests.java1
-rw-r--r--luni/src/test/java/java/text/SimpleDateFormatTest.java39
3 files changed, 43 insertions, 3 deletions
diff --git a/luni/src/main/java/java/text/SimpleDateFormat.java b/luni/src/main/java/java/text/SimpleDateFormat.java
index 815a4dc936..c9105746e6 100644
--- a/luni/src/main/java/java/text/SimpleDateFormat.java
+++ b/luni/src/main/java/java/text/SimpleDateFormat.java
@@ -967,7 +967,7 @@ public class SimpleDateFormat extends DateFormat {
* Returns the date which is the start of the one hundred year period for two-digit year values.
*/
public Date get2DigitYearStart() {
- return defaultCenturyStart;
+ return (Date) defaultCenturyStart.clone();
}
/**
@@ -1332,9 +1332,9 @@ public class SimpleDateFormat extends DateFormat {
* Sets the date which is the start of the one hundred year period for two-digit year values.
*/
public void set2DigitYearStart(Date date) {
- defaultCenturyStart = date;
+ defaultCenturyStart = (Date) date.clone();
Calendar cal = new GregorianCalendar();
- cal.setTime(date);
+ cal.setTime(defaultCenturyStart);
creationYear = cal.get(Calendar.YEAR);
}
diff --git a/luni/src/test/java/java/text/AllTests.java b/luni/src/test/java/java/text/AllTests.java
index 240b745ffb..ca13ff8275 100644
--- a/luni/src/test/java/java/text/AllTests.java
+++ b/luni/src/test/java/java/text/AllTests.java
@@ -28,6 +28,7 @@ public class AllTests {
suite.addTestSuite(java.text.DecimalFormatSymbolsTest.class);
suite.addTestSuite(java.text.NormalizerTest.class);
suite.addTestSuite(java.text.NumberFormatTest.class);
+ suite.addTestSuite(java.text.SimpleDateFormatTest.class);
return suite;
}
}
diff --git a/luni/src/test/java/java/text/SimpleDateFormatTest.java b/luni/src/test/java/java/text/SimpleDateFormatTest.java
new file mode 100644
index 0000000000..9d34024905
--- /dev/null
+++ b/luni/src/test/java/java/text/SimpleDateFormatTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.text;
+
+import java.util.Date;
+
+public class SimpleDateFormatTest extends junit.framework.TestCase {
+ // The RI fails this test.
+ public void test2DigitYearStartIsCloned() throws Exception {
+ // Test that get2DigitYearStart returns a clone.
+ SimpleDateFormat sdf = new SimpleDateFormat();
+ Date originalDate = sdf.get2DigitYearStart();
+ assertNotSame(sdf.get2DigitYearStart(), originalDate);
+ assertEquals(sdf.get2DigitYearStart(), originalDate);
+ originalDate.setTime(0);
+ assertFalse(sdf.get2DigitYearStart().equals(originalDate));
+ // Test that set2DigitYearStart takes a clone.
+ Date newDate = new Date();
+ sdf.set2DigitYearStart(newDate);
+ assertNotSame(sdf.get2DigitYearStart(), newDate);
+ assertEquals(sdf.get2DigitYearStart(), newDate);
+ newDate.setTime(0);
+ assertFalse(sdf.get2DigitYearStart().equals(newDate));
+ }
+}