Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Aug 6, 2024
1 parent f5c9e8f commit 4a03582
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -62,6 +62,7 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import jdk.internal.util.StaticProperty;
import sun.security.action.GetPropertyAction;
import sun.util.resources.LocaleData;
import sun.util.resources.OpenListResourceBundle;
Expand Down Expand Up @@ -289,6 +290,17 @@ public String getCurrencyName(String key) {
}

public String getLocaleName(String key) {
// Old ISO code hack. get names for old iso codes
// bundles contain the keys for the new iso codes
if (StaticProperty.javaLocaleUseOldISOCodes().equalsIgnoreCase("true")) {
key = switch (key) {
case "iw" -> "he";
case "in" -> "id";
case "ji" -> "yi";
default -> key;
};
}

Object localeName = null;
String cacheKey = LOCALE_NAMES + key;

Expand Down
35 changes: 33 additions & 2 deletions test/jdk/java/util/Locale/LocaleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
/*
* @test
* @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
* 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
* 4147315 4147317 4147552 4335196 4778440 4940539 5010672 6475525 6544471 6627549
* 6786276 7066203 7085757 8008577 8030696 8170840 8174269 8255086 8263202 8287868
* 8337603
* @summary test Locales
* @modules jdk.localedata
* @run junit LocaleTest
Expand Down Expand Up @@ -84,9 +85,13 @@
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class LocaleTest {
Expand Down Expand Up @@ -734,6 +739,32 @@ public void TestChangedISO639Codes() {

}

/**
* @bug 8337603
*/
static Stream<Arguments> changedISOCodes() {
var hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";
var yiddish = "\u05d9\u05d9\u05b4\u05d3\u05d9\u05e9";
var indonesian = "Indonesia";

return Stream.of(
Arguments.of("he", hebrew),
Arguments.of("iw", hebrew),
Arguments.of("yi", yiddish),
Arguments.of("ji", yiddish),
Arguments.of("id", indonesian),
Arguments.of("in", indonesian)
);
}
@ParameterizedTest
@MethodSource("changedISOCodes")
public void TestOldISOCodeLanguageName(String code, String expected) {
var loc = Locale.of(code);
assertEquals(expected,
loc.getDisplayName(loc),
"java.locale.useOldISOCodes=" + System.getProperty("java.locale.useOldISOCodes"));
}

/**
* @bug 4092475
* I could not reproduce this bug. I'm pretty convinced it was fixed with the
Expand Down

0 comments on commit 4a03582

Please sign in to comment.