diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java index cd6c03614b3..e9d9f999c3c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java @@ -2192,15 +2192,15 @@ public final class ULocale implements Serializable { * Utility to fetch locale display data from resource bundle tables. */ private static String getTableString(String tableName, String subtableName, String item, String displayLocaleID) { - if (item.length() > 0) { - try { + try { + if (item.length() > 0) { ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle. getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, displayLocaleID); return getTableString(tableName, subtableName, item, bundle); - } catch (Exception e) { -// System.out.println("gtsu: " + e.getMessage()); } - } + } catch (Exception e) { +// System.out.println("gtsu: " + e.getMessage()); + } return item; } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index 414ae8c71af..3ff01d6a0ef 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -3848,4 +3848,19 @@ public class ULocaleTest extends TestFmwk { } } } + + /* + * Test that if you use any locale without keyword that you will get a NULL + * string returned and not throw and exception. + */ + public void Test4735() + { + try { + new ULocale("und").getDisplayKeywordValue("calendar",ULocale.GERMAN); + new ULocale("en").getDisplayKeywordValue("calendar",ULocale.GERMAN); + } catch (Exception e) { + errln("Unexpected exception: " + e.getMessage()); + } + } + }