]> granicus.if.org Git - icu/commitdiff
ICU-10136 Do not throw an exception when requesting the quotes for fr_CA. It should...
authorGeorge Rhoten <grhoten@users.noreply.github.com>
Wed, 1 May 2013 21:37:14 +0000 (21:37 +0000)
committerGeorge Rhoten <grhoten@users.noreply.github.com>
Wed, 1 May 2013 21:37:14 +0000 (21:37 +0000)
X-SVN-Rev: 33568

icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleDataTest.java

index 30d557bd47db79e6ff70606bd270292ab0a7032d..92f29c346b4591f5b833004afbeee8b230f27da8 100644 (file)
@@ -247,6 +247,13 @@ public final class LocaleData {
        return noSubstitute;
     }
 
+    private static final String [] DELIMITER_TYPES = {
+                                 "quotationStart", 
+                                 "quotationEnd", 
+                                 "alternateQuotationStart", 
+                                 "alternateQuotationEnd"
+    };
+
     /**
      * Retrieves a delimiter string from the locale data.
      *
@@ -257,12 +264,9 @@ public final class LocaleData {
      * @stable ICU 3.4
      */
     public String getDelimiter(int type) {
-        String [] delimiterTypes = { "quotationStart", 
-                                     "quotationEnd", 
-                                     "alternateQuotationStart", 
-                                     "alternateQuotationEnd" };
-
-        ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get("delimiters").get(delimiterTypes[type]);
+        ICUResourceBundle delimitersBundle = (ICUResourceBundle) bundle.get("delimiters");
+        // Only some of the quotation marks may be here. So we make sure that we do a multilevel fallback.
+        ICUResourceBundle stringBundle = delimitersBundle.getWithFallback(DELIMITER_TYPES[type]);
 
         if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) )
            return null;
index c64c707f560eba8418548492d8a0af2db8450cad..c8efa7389ad3814283a15587448a14a397bb2c8d 100644 (file)
@@ -355,6 +355,17 @@ public class LocaleDataTest extends TestFmwk{
         logln(ld.getDelimiter(LocaleData.ALT_QUOTATION_END));
     }
 
+    public void TestFallback(){
+        LocaleData fr_FR = LocaleData.getInstance(ULocale.FRANCE);
+        LocaleData fr_CA = LocaleData.getInstance(ULocale.CANADA_FRENCH);
+
+        // This better not crash when only some values are overridden
+        assertEquals("Start quotes are not equal", fr_FR.getDelimiter(LocaleData.QUOTATION_START), fr_CA.getDelimiter(LocaleData.QUOTATION_START));
+        assertEquals("End quotes are not equals", fr_FR.getDelimiter(LocaleData.QUOTATION_END), fr_CA.getDelimiter(LocaleData.QUOTATION_END));
+        assertNotEquals("Alt start quotes are equal", fr_FR.getDelimiter(LocaleData.ALT_QUOTATION_START), fr_CA.getDelimiter(LocaleData.ALT_QUOTATION_START));
+        assertNotEquals("Alt end quotes are equals", fr_FR.getDelimiter(LocaleData.ALT_QUOTATION_END), fr_CA.getDelimiter(LocaleData.ALT_QUOTATION_END));
+    }
+
     public void TestLocaleDisplayPattern(){
         LocaleData ld = LocaleData.getInstance();
         logln("Default locale "+ " LocaleDisplayPattern:" + ld.getLocaleDisplayPattern());