8220227: Host Locale Provider getDisplayCountry returns error message under non-English Win10
Adjusting to detect translated Unknown messages
Reviewed-by: naoto
diff --git a/src/java.base/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java b/src/java.base/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java
index 2f4fd0e..85deffa 100644
--- a/src/java.base/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java
+++ b/src/java.base/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -510,8 +510,15 @@
public String getDisplayCountry(String countryCode, Locale locale) {
// Retrieves the display country name by calling
// GetLocaleInfoEx(LOCALE_SLOCALIZEDCOUNTRYNAME).
- return getDisplayString(locale.toLanguageTag(),
- DN_LOCALE_REGION, nativeDisplayLanguage+"-"+countryCode);
+ String str = getDisplayString(locale.toLanguageTag(),
+ DN_LOCALE_REGION,
+ nativeDisplayLanguage+"-"+countryCode);
+ // Hack: Windows 10 returns translated "Unknown Region (XX)"
+ // for localized XX region name. Take that as not known.
+ if (str != null && str.endsWith("("+countryCode+")")) {
+ return null;
+ }
+ return str;
}
@Override
diff --git a/src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c b/src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c
index 28663f7..8c1001a 100644
--- a/src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c
+++ b/src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -168,11 +168,6 @@
}
};
-
-// Localized region name for unknown regions (Windows 10)
-#define UNKNOWN_REGION L"Unknown Region ("
-#define UNKNOWN_REGION_SIZE wcslen(UNKNOWN_REGION)
-
/*
* Class: sun_util_locale_provider_HostLocaleProviderAdapterImpl
* Method: initialize
@@ -755,15 +750,10 @@
(*env)->ReleaseStringChars(env, jStr, pjChar);
if (got) {
- // Hack: Windows 10 returns "Unknown Region (XX)" for localized XX region name.
- // Take that as not known.
- if (type != sun_util_locale_provider_HostLocaleProviderAdapterImpl_DN_LOCALE_REGION ||
- wcsncmp(UNKNOWN_REGION, buf, UNKNOWN_REGION_SIZE) != 0) {
- return (*env)->NewString(env, buf, (jsize)wcslen(buf));
- }
+ return (*env)->NewString(env, buf, (jsize)wcslen(buf));
+ } else {
+ return NULL;
}
-
- return NULL;
}
int getLocaleInfoWrapper(const jchar *langtag, LCTYPE type, LPWSTR data, int buflen) {
diff --git a/test/jdk/java/util/Locale/LocaleProviders.java b/test/jdk/java/util/Locale/LocaleProviders.java
index 230d11c..c155893 100644
--- a/test/jdk/java/util/Locale/LocaleProviders.java
+++ b/test/jdk/java/util/Locale/LocaleProviders.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -72,6 +72,10 @@
bug8027289Test(args[1]);
break;
+ case "bug8220227Test":
+ bug8220227Test();
+ break;
+
default:
throw new RuntimeException("Test method '"+methodName+"' not found.");
}
@@ -245,4 +249,15 @@
throw new RuntimeException("Unexpected Chinese currency symbol. returned: " + formatted + ", expected: " + expectedSymbol[0]);
}
}
+
+ static void bug8220227Test() {
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ Locale l = new Locale("xx","XX");
+ String country = l.getDisplayCountry();
+ if (country.endsWith("(XX)")) {
+ throw new RuntimeException(
+ "Unexpected Region name: " + country);
+ }
+ }
+ }
}
diff --git a/test/jdk/java/util/Locale/LocaleProviders.sh b/test/jdk/java/util/Locale/LocaleProviders.sh
index cb8a7c6..652dadf 100644
--- a/test/jdk/java/util/Locale/LocaleProviders.sh
+++ b/test/jdk/java/util/Locale/LocaleProviders.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2019, 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
@@ -25,7 +25,7 @@
# @test
# @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577
# 8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006
-# 8150432
+# 8150432 8220227
# @summary tests for "java.locale.providers" system property
# @modules java.base/sun.util.locale
# java.base/sun.util.locale.provider
@@ -367,4 +367,15 @@
runTest
fi
+# testing 8220227 fix. (Windows only)
+if [ "${DEFFMTLANG}" != "en" ]; then
+ METHODNAME=bug8220227Test
+ PREFLIST=HOST
+ PARAM1=
+ PARAM2=
+ PARAM3=
+ SPICLASSES=
+ runTest
+fi
+
exit $result