diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/Units.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/Units.java index e8ef091dcda..68e4e9f9825 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/Units.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/Units.java @@ -109,10 +109,12 @@ public static TypeAndCore splitUnit(String longOrShortUnit, TypeAndCore typeAndC } public static String getShort(String longUnit) { - return LONG_TO_SHORT.get(longUnit); + String result = LONG_TO_SHORT.get(longUnit); + return result == null ? longUnit : result; } public static String getLong(String shortId) { - return LONG_TO_SHORT.inverse().get(shortId); + String result = LONG_TO_SHORT.inverse().get(shortId); + return result == null ? shortId : result; } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java index a2c94c4cd6e..f0cb225c4a4 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java @@ -4382,7 +4382,31 @@ public void testPreferencesWithLocales() { "default", "en-u-mu-stone", Rational.TWO, - "stone")); + "stone"), + List.of( + 1, + MeasureUnit.forIdentifier( + "candela"), // a unit whose quantity has no preference data + "default", + "en", + Rational.ONE, + "candela"), + List.of( + 1, + MeasureUnit.forIdentifier( + "candela-per-byte"), // a unit that has no quantity + "default", + "en", + Rational.of(1, 8), + "candela-per-bit"), + List.of( + 1, + MeasureUnit.forIdentifier( + "candela-per-cubic-foot"), // a unit that has no quantity + "default", + "en", + Rational.of(1953125000, 55306341), + "candela-per-cubic-meter")); for (boolean isICU : List.of(false, true)) { for (List test : tests) { String actualUnit; @@ -4400,16 +4424,15 @@ public void testPreferencesWithLocales() { Rational rationalAmount = Rational.of(sourceAmount.toString()); UnitPreferences prefs = SDI.getUnitPreferences(); final ULocale uLocale = ULocale.forLanguageTag(languageTag); - UnitPreference unitPreference1 = + UnitPreference unitPreference = prefs.getUnitPreference( rationalAmount, sourceUnitString, usage, uLocale); - if (unitPreference1 == null) { // if the quantity isn't found + if (unitPreference == null) { // if the quantity isn't found throw new IllegalArgumentException( String.format( "No unit preferences found for unit: %s, usage: %s, locale:%s", sourceUnitString, usage, languageTag)); } - UnitPreference unitPreference = unitPreference1; actualUnit = unitPreference.unit; actualValue = converter.convert(