mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-20629 DTPG: Fixing uncaught exception in Java.
This commit is contained in:
parent
6671947d3e
commit
d846d72bba
3 changed files with 19 additions and 3 deletions
icu4c/source/test/intltest
icu4j/main
classes/core/src/com/ibm/icu/text
tests/core/src/com/ibm/icu/dev/test/format
|
@ -1416,6 +1416,11 @@ void IntlTestDateTimePatternGeneratorAPI::test20640_HourCyclArsEnNH() {
|
|||
{"ars", u"h a", u"h:mm a"},
|
||||
// en_NH is interesting because NH is a depregated region code.
|
||||
{"en_NH", u"h a", u"h:mm a"},
|
||||
// ch_ZH is a typo (should be zh_CN), but we should fail gracefully.
|
||||
// {"cn_ZH", u"HH", u"H:mm"}, // TODO(ICU-20653): Desired behavior
|
||||
{"cn_ZH", u"HH", u"h:mm a"}, // Actual behavior
|
||||
// a non-BCP47 locale without a country code should not fail
|
||||
{"ja_TRADITIONAL", u"H時", u"H:mm"},
|
||||
};
|
||||
|
||||
for (auto& cas : cases) {
|
||||
|
|
|
@ -351,6 +351,8 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
|
|||
String language = uLocale.getLanguage();
|
||||
String country = uLocale.getCountry();
|
||||
if (language.isEmpty() || country.isEmpty()) {
|
||||
// Note: addLikelySubtags is documented not to throw in Java,
|
||||
// unlike in C++.
|
||||
ULocale max = ULocale.addLikelySubtags(uLocale);
|
||||
language = max.getLanguage();
|
||||
country = max.getCountry();
|
||||
|
@ -368,9 +370,13 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
|
|||
|
||||
// Check if the region has an alias
|
||||
if (list == null) {
|
||||
Region region = Region.getInstance(country);
|
||||
country = region.toString();
|
||||
list = getAllowedHourFormatsLangCountry(language, country);
|
||||
try {
|
||||
Region region = Region.getInstance(country);
|
||||
country = region.toString();
|
||||
list = getAllowedHourFormatsLangCountry(language, country);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// invalid region; fall through
|
||||
}
|
||||
}
|
||||
|
||||
if (list != null) {
|
||||
|
|
|
@ -1736,6 +1736,11 @@ public class DateTimeGeneratorTest extends TestFmwk {
|
|||
{"ars", "h a", "h:mm a"},
|
||||
// en_NH is interesting because NH is a depregated region code.
|
||||
{"en_NH", "h a", "h:mm a"},
|
||||
// ch_ZH is a typo (should be zh_CN), but we should fail gracefully.
|
||||
// {"cn_ZH", "HH", "H:mm"}, // TODO(ICU-20653): Desired behavior
|
||||
{"cn_ZH", "HH", "h:mm a"}, // Actual behavior
|
||||
// a non-BCP47 locale without a country code should not fail
|
||||
{"ja_TRADITIONAL", "H時", "H:mm"},
|
||||
};
|
||||
|
||||
for (String[] cas : cases) {
|
||||
|
|
Loading…
Add table
Reference in a new issue