From c55b3819a62b325fb722fd0708bdbfc62cff9477 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Wed, 1 May 2013 21:37:14 +0000 Subject: [PATCH] ICU-10136 Do not throw an exception when requesting the quotes for fr_CA. It should fallback to data from fr. X-SVN-Rev: 33568 --- .../core/src/com/ibm/icu/util/LocaleData.java | 16 ++++++++++------ .../ibm/icu/dev/test/util/LocaleDataTest.java | 11 +++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java index 30d557bd47d..92f29c346b4 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleData.java @@ -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; diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleDataTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleDataTest.java index c64c707f560..c8efa7389ad 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleDataTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleDataTest.java @@ -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());