ICU-9140 Fixed ChineseDateFormatSymbols initialization problem revealed by the recent change.

X-SVN-Rev: 31960
This commit is contained in:
Yoshito Umaoka 2012-06-15 19:46:41 +00:00
parent 78bb22cdb9
commit 37d5ca4c7b
2 changed files with 20 additions and 9 deletions

View file

@ -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 <code>FORMAT</code> 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}", ""): "";
}
}

View file

@ -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);
}