Skip to content

Commit

Permalink
8317443: StackOverflowError on calling ListFormat::getInstance() for …
Browse files Browse the repository at this point in the history
…Norwegian locales

Reviewed-by: joehw
  • Loading branch information
naotoj committed Oct 5, 2023
1 parent a1c9587 commit 8a30c2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,20 @@ public String[] getListPatterns(ListFormat.Type type, ListFormat.Style style) {
ResourceReference data = cache.get(cacheKey);

if (data == null || ((lpArray = (String[]) data.get()) == null)) {
ResourceBundle rb = localeData.getDateFormatData(locale);
lpArray = rb.getStringArray("ListPatterns_" + typeStr + (style == ListFormat.Style.FULL ? "" : "-" + styleStr));
var rbKey = "ListPatterns_" + typeStr + (style == ListFormat.Style.FULL ? "" : "-" + styleStr);
lpArray = localeData.getDateFormatData(locale).getStringArray(rbKey);

if (lpArray[0].isEmpty() || lpArray[1].isEmpty() || lpArray[2].isEmpty()) {
var adapter = LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR);
if (adapter instanceof ResourceBundleBasedAdapter rbba) {
if (LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.CLDR)
instanceof ResourceBundleBasedAdapter rbba) {
var candList = rbba.getCandidateLocales("", locale);
// make sure there is at least one parent locale
if (candList.size() >= 2) {
var parentPatterns = adapter.getLocaleResources(candList.get(1)).getListPatterns(type, style);
for (int i = 0; i < 3; i++) { // exclude optional ones, ie, "two"/"three"
if (lpArray[i].isEmpty()) {
lpArray[i] = parentPatterns[i];
if (!candList.isEmpty()) {
for (var p : candList.subList(1, candList.size())) {
var parentPatterns = localeData.getDateFormatData(p).getStringArray(rbKey);
for (int i = 0; i < 3; i++) { // exclude optional ones, ie, "two"/"three"
if (lpArray[i].isEmpty()) {
lpArray[i] = parentPatterns[i];
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions test/jdk/java/text/Format/ListFormat/TestListFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ void getInstance_3Arg_InheritanceValidation() {
// English ("en") has Oxford-comma "end" pattern. Thus missing "standard"/"middle"
// should be inherited from "en", but "end" should stay non-Oxford for "en-001"
// Note that this test depends on a particular version of CLDR data.
var world = Locale.forLanguageTag("en-001");
assertEquals("""
ListFormat [locale: "English (world)", start: "{0}, {1}", middle: "{0}, {1}", end: "{0} and {1}", two: "{0} and {1}", three: "{0}, {1} and {2}"]
""",
ListFormat.getInstance(Locale.forLanguageTag("en-001"), ListFormat.Type.STANDARD, ListFormat.Style.FULL).toString());
ListFormat [locale: "%s", start: "{0}, {1}", middle: "{0}, {1}", end: "{0} and {1}", two: "{0} and {1}", three: "{0}, {1} and {2}"]
""".formatted(world.getDisplayName()),
ListFormat.getInstance(world, ListFormat.Type.STANDARD, ListFormat.Style.FULL).toString());
}

private static void compareResult(ListFormat f, List<String> input, String expected, boolean roundTrip) throws ParseException {
Expand Down

1 comment on commit 8a30c2a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.