Skip to content

Commit

Permalink
8272352: Java launcher can not parse Chinese character when system lo…
Browse files Browse the repository at this point in the history
…cale is set to UTF-8

Reviewed-by: clanger
Backport-of: 011b96c
  • Loading branch information
Stephanie Crater authored and RealCLanger committed Jul 22, 2022
1 parent 5a1377d commit 1a66d5a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/java.base/windows/native/libjava/java_props_md.c
Expand Up @@ -63,22 +63,24 @@ static boolean SetupI18nProps(LCID lcid, char** language, char** script, char**
static char *
getEncodingInternal(LCID lcid)
{
int codepage;
int codepage = 0;
char * ret = malloc(16);
if (ret == NULL) {
return NULL;
}

if (GetLocaleInfo(lcid,
if (lcid == 0) { // for sun.jnu.encoding
codepage = GetACP();
_itoa_s(codepage, ret + 2, 14, 10);
} else if (GetLocaleInfo(lcid,
LOCALE_IDEFAULTANSICODEPAGE,
ret+2, 14) == 0) {
codepage = 1252;
} else {
codepage = atoi(ret+2);
ret + 2, 14) != 0) {
codepage = atoi(ret + 2);
}

switch (codepage) {
case 0:
case 65001:
strcpy(ret, "UTF-8");
break;
case 874: /* 9:Thai */
Expand Down Expand Up @@ -667,7 +669,6 @@ GetJavaProperties(JNIEnv* env)
* (which is a Windows LCID value),
*/
LCID userDefaultLCID = GetUserDefaultLCID();
LCID systemDefaultLCID = GetSystemDefaultLCID();
LANGID userDefaultUILang = GetUserDefaultUILanguage();
LCID userDefaultUILCID = MAKELCID(userDefaultUILang, SORTIDFROMLCID(userDefaultLCID));

Expand Down Expand Up @@ -706,7 +707,10 @@ GetJavaProperties(JNIEnv* env)
&sprops.display_variant,
&display_encoding);

sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID);
sprops.sun_jnu_encoding = getEncodingInternal(0);
if (sprops.sun_jnu_encoding == NULL) {
sprops.sun_jnu_encoding = "UTF-8";
}
if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) {
// MS claims "Vista has built-in support for HKSCS-2004.
// All of the HKSCS-2004 characters have Unicode 4.1.
Expand Down

1 comment on commit 1a66d5a

@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.