]> granicus.if.org Git - icu/commitdiff
ICU-9140 Fixed ChineseDateFormatSymbols initialization problem revealed by the recent...
authorYoshito Umaoka <y.umaoka@gmail.com>
Fri, 15 Jun 2012 19:46:41 +0000 (19:46 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Fri, 15 Jun 2012 19:46:41 +0000 (19:46 +0000)
X-SVN-Rev: 31960

icu4j/main/classes/core/src/com/ibm/icu/text/ChineseDateFormatSymbols.java
icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java

index a106d4fe0f599be8dc86d2df4456085e136be96f..20d37aac985563cf8d4b8161a17b588ddd0b193e 100644 (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}", ""): "";
+    }
 }
index 786e8ef759f4e0e6435525da02146e15b5f6c713..25b4526d8c311ca14d8c6ff3061ef850d292835f 100644 (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);
         }