Skip to content

Commit 3d07b3c

Browse files
committed
8282227: Locale information for nb is not working properly
Reviewed-by: rriggs
1 parent cfe67af commit 3d07b3c

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -238,6 +238,8 @@ public List<Locale> getCandidateLocales(String baseName, Locale locale) {
238238
return applyParentLocales(baseName, candidates);
239239
}
240240

241+
private static final Locale NB = Locale.forLanguageTag("nb");
242+
private static final Locale NO = Locale.forLanguageTag("no");
241243
private List<Locale> applyParentLocales(String baseName, List<Locale> candidates) {
242244
// check irregular parents
243245
for (int i = 0; i < candidates.size(); i++) {
@@ -247,11 +249,15 @@ private List<Locale> applyParentLocales(String baseName, List<Locale> candidates
247249
if (p != null &&
248250
!candidates.get(i+1).equals(p)) {
249251
List<Locale> applied = candidates.subList(0, i+1);
250-
if (applied.contains(p)) {
251-
// avoid circular recursion (could happen with nb/no case)
252-
continue;
252+
// Tweak for Norwegian locales, CLDR switched the canonical form of
253+
// Norwegian Bokmal language code from "nb" to "no" in CLDR 39
254+
// (https://unicode-org.atlassian.net/browse/CLDR-2698)
255+
if (p.equals(NB) || p.equals(NO)) {
256+
applied.add(NO);
257+
applied.add(Locale.ROOT);
258+
} else {
259+
applied.addAll(applyParentLocales(baseName, super.getCandidateLocales(baseName, p)));
253260
}
254-
applied.addAll(applyParentLocales(baseName, super.getCandidateLocales(baseName, p)));
255261
return applied;
256262
}
257263
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8282227
27+
* @modules jdk.localedata
28+
* @summary Checks Norwegian locale fallback retrieves resource bundles correctly.
29+
* @run main/othervm -Djava.locale.providers=COMPAT NorwegianFallbackTest nb
30+
* @run main/othervm -Djava.locale.providers=COMPAT NorwegianFallbackTest nn
31+
* @run main/othervm -Djava.locale.providers=COMPAT NorwegianFallbackTest no
32+
* @run main/othervm -Djava.locale.providers=CLDR NorwegianFallbackTest nb
33+
* @run main/othervm -Djava.locale.providers=CLDR NorwegianFallbackTest nn
34+
* @run main/othervm -Djava.locale.providers=CLDR NorwegianFallbackTest no
35+
*/
36+
37+
import java.text.DateFormatSymbols;
38+
import java.util.List;
39+
import java.util.Locale;
40+
import static java.util.Calendar.SUNDAY;
41+
42+
public class NorwegianFallbackTest {
43+
44+
private final static String SUN_ROOT = DateFormatSymbols.getInstance(Locale.ROOT).getShortWeekdays()[SUNDAY];
45+
private final static List<Locale> TEST_LOCS = List.of(
46+
Locale.forLanguageTag("nb"),
47+
Locale.forLanguageTag("nn"),
48+
Locale.forLanguageTag("no")
49+
);
50+
51+
public static void main(String... args) {
52+
// Dummy instance
53+
var startup_loc = Locale.forLanguageTag(args[0]);
54+
DateFormatSymbols.getInstance(startup_loc);
55+
56+
TEST_LOCS.stream()
57+
.peek(l -> System.out.print("Testing locale: " + l + ", (startup locale: " + startup_loc + ")... "))
58+
.map(l -> DateFormatSymbols.getInstance(l).getShortWeekdays()[SUNDAY])
59+
.forEach(sun -> {
60+
if (sun.equals(SUN_ROOT)) {
61+
throw new RuntimeException("Norwegian fallback failed");
62+
} else {
63+
System.out.println("Got " + "\"" + sun + "\" for Sunday short name");
64+
}
65+
});
66+
}
67+
}

0 commit comments

Comments
 (0)