From 37d5ca4c7b459f660157ae1373b07a5e6148b31a Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Fri, 15 Jun 2012 19:46:41 +0000 Subject: [PATCH] ICU-9140 Fixed ChineseDateFormatSymbols initialization problem revealed by the recent change. X-SVN-Rev: 31960 --- .../icu/text/ChineseDateFormatSymbols.java | 22 +++++++++++++------ .../com/ibm/icu/text/DateFormatSymbols.java | 7 ++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java index a106d4fe0f5..20d37aac985 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java @@ -32,7 +32,7 @@ public class ChineseDateFormatSymbols extends DateFormatSymbols { * Package-private array that ChineseDateFormat needs to be able to * read. */ - String isLeapMonth[]; // Do NOT add =null initializer + String[] isLeapMonth; /** * Construct a ChineseDateFormatSymbols for the default FORMAT locale. @@ -95,18 +95,26 @@ public class ChineseDateFormatSymbols extends DateFormatSymbols { */ protected void initializeData(ULocale loc, CalendarData calData) { super.initializeData(loc, calData); - // The old way, obsolete: - //isLeapMonth = calData.getStringArray("isLeapMonth"); - // The new way to fake this for backward compatibility (no longer used to format/parse): - isLeapMonth = new String[2]; - isLeapMonth[0] = ""; - isLeapMonth[1] = (leapMonthPatterns != null)? leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_WIDE].replace("{0}", ""): ""; + initializeIsLeapMonth(); } void initializeData(DateFormatSymbols dfs) { super.initializeData(dfs); if (dfs instanceof ChineseDateFormatSymbols) { + // read-only array, no need to clone this.isLeapMonth = ((ChineseDateFormatSymbols)dfs).isLeapMonth; + } else { + initializeIsLeapMonth(); } } + + private void initializeIsLeapMonth() { + // The old way, obsolete: + //isLeapMonth = calData.getStringArray("isLeapMonth"); + // The new way to fake this for backward compatibility (no longer used to format/parse): + + isLeapMonth = new String[2]; + isLeapMonth[0] = ""; + isLeapMonth[1] = (leapMonthPatterns != null)? leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_WIDE].replace("{0}", ""): ""; + } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java index 786e8ef759f..25b4526d8c3 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java @@ -1148,8 +1148,11 @@ public class DateFormatSymbols implements Serializable, Cloneable { // Initialize data from scratch put a clone of this instance into the cache CalendarData calData = new CalendarData(desiredLocale, type); initializeData(desiredLocale, calData); - dfs = (DateFormatSymbols)this.clone(); - DFSCACHE.put(key, dfs); + // Do not cache subclass instances + if (this.getClass().getName().equals("com.ibm.icu.text.DateFormatSymbols")) { + dfs = (DateFormatSymbols)this.clone(); + DFSCACHE.put(key, dfs); + } } else { initializeData(dfs); }