Skip to content

Commit 4dc1305

Browse files
gnu-andrewjerboaa
andcommitted
8301119: Support for GB18030-2022
8310947: gb18030-2000 not selectable with LANG=zh_CN.GB18030 after JDK-8301119 Co-authored-by: Severin Gehwolf <sgehwolf@openjdk.org> Reviewed-by: stuefe, sgehwolf Backport-of: 5c4e744dabcf7785c35168db5d0458ccebfd41e6
1 parent e575cb3 commit 4dc1305

File tree

9 files changed

+979
-115
lines changed

9 files changed

+979
-115
lines changed

jdk/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131
import java.util.ArrayList;
3232
import java.util.TreeMap;
3333
import java.util.Iterator;
34-
import java.util.Locale;
3534
import java.util.Map;
3635
import sun.misc.ASCIICaseInsensitiveComparator;
3736

38-
3937
/**
4038
* Abstract base class for charset providers.
4139
*

jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2023, 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
@@ -25,11 +25,9 @@
2525

2626
package sun.nio.cs.ext;
2727

28-
import java.lang.ref.SoftReference;
29-
import java.nio.charset.Charset;
30-
import java.nio.charset.spi.CharsetProvider;
3128
import sun.nio.cs.AbstractCharsetProvider;
3229
import java.security.AccessController;
30+
3331
import sun.security.action.GetPropertyAction;
3432

3533

@@ -115,9 +113,11 @@ public ExtendedCharsets() {
115113
"CP936"
116114
});
117115

116+
// The definition of this charset may be overridden by the init method
117+
// below, if the jdk.charset.GB18030 property is set
118118
charset("GB18030", "GB18030",
119119
new String[] {
120-
"gb18030-2000"
120+
"gb18030-2022"
121121
});
122122

123123
charset("GB2312", "EUC_CN",
@@ -1136,14 +1136,15 @@ public ExtendedCharsets() {
11361136
}
11371137

11381138
private boolean initialized = false;
1139+
private boolean isGB18030_2000 = false;
11391140

1140-
// If the sun.nio.cs.map property is defined on the command line we won't
1141-
// see it in the system-properties table until after the charset subsystem
1142-
// has been initialized. We therefore delay the effect of this property
1143-
// until after the JRE has completely booted.
1141+
// If the sun.nio.cs.map and/or jdk.charset.GB18030 properties are defined
1142+
// on the command line we won't see them in the system-properties table until
1143+
// after the charset subsystem has been initialized. We therefore delay
1144+
// the effect of these property until after the JRE has completely booted.
11441145
//
1145-
// At the moment following values for this property are supported, property
1146-
// value string is case insensitive.
1146+
// At the moment the following values for the sun.nio.cs.map property are
1147+
// supported and the property value string is case insensitive.
11471148
//
11481149
// (1)"Windows-31J/Shift_JIS"
11491150
// In 1.4.1 we added a correct implementation of the Shift_JIS charset
@@ -1176,6 +1177,10 @@ public ExtendedCharsets() {
11761177
// where each charset named to the left of a slash is intended to replace
11771178
// (most) uses of the charset named to the right of the slash.
11781179
//
1180+
// The jdk.charset.GB18030 property is simpler and accepts only the value
1181+
// "2000". If this value is given, the older GB18030-2000 variant of the
1182+
// character set replaces the default GB18030-2022 variant.
1183+
//
11791184
protected void init() {
11801185
if (initialized)
11811186
return;
@@ -1184,6 +1189,8 @@ protected void init() {
11841189

11851190
String map = AccessController.doPrivileged(
11861191
new GetPropertyAction("sun.nio.cs.map"));
1192+
boolean isGB18030_2000 = "2000".equals(AccessController.doPrivileged(
1193+
new GetPropertyAction("jdk.charset.GB18030")));
11871194
boolean sjisIsMS932 = false;
11881195
boolean iso2022jpIsMS50221 = false;
11891196
boolean iso2022jpIsMS50220 = false;
@@ -1202,6 +1209,16 @@ protected void init() {
12021209
}
12031210
}
12041211
}
1212+
if (isGB18030_2000) {
1213+
deleteCharset("GB18030",
1214+
new String[] {
1215+
"gb18030-2022"
1216+
});
1217+
charset("GB18030", "GB18030",
1218+
new String[] {
1219+
"gb18030-2000"
1220+
});
1221+
}
12051222
if (sjisIsMS932) {
12061223
deleteCharset("Shift_JIS",
12071224
new String[] {
@@ -1314,6 +1331,7 @@ protected void init() {
13141331
"x-compound-text"
13151332
});
13161333
}
1334+
this.isGB18030_2000 = isGB18030_2000;
13171335
initialized = true;
13181336
}
13191337

@@ -1322,4 +1340,14 @@ public static String[] aliasesFor(String charsetName) {
13221340
return null;
13231341
return instance.aliases(charsetName);
13241342
}
1343+
1344+
static boolean IS_2000() {
1345+
if (instance == null) {
1346+
return false;
1347+
}
1348+
if (!instance.initialized) {
1349+
instance.init();
1350+
}
1351+
return instance.isGB18030_2000;
1352+
}
13251353
}

0 commit comments

Comments
 (0)