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
This commit is contained in:
Andrew John Hughes 2023-07-13 16:33:19 +00:00
parent e575cb38f0
commit 4dc1305caf
9 changed files with 980 additions and 116 deletions

View File

@ -31,11 +31,9 @@ import java.nio.charset.spi.CharsetProvider;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import sun.misc.ASCIICaseInsensitiveComparator;
/**
* Abstract base class for charset providers.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, 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,11 +25,9 @@
package sun.nio.cs.ext;
import java.lang.ref.SoftReference;
import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
import sun.nio.cs.AbstractCharsetProvider;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
@ -115,9 +113,11 @@ public class ExtendedCharsets
"CP936"
});
// The definition of this charset may be overridden by the init method
// below, if the jdk.charset.GB18030 property is set
charset("GB18030", "GB18030",
new String[] {
"gb18030-2000"
"gb18030-2022"
});
charset("GB2312", "EUC_CN",
@ -1136,14 +1136,15 @@ public class ExtendedCharsets
}
private boolean initialized = false;
private boolean isGB18030_2000 = false;
// If the sun.nio.cs.map property is defined on the command line we won't
// see it in the system-properties table until after the charset subsystem
// has been initialized. We therefore delay the effect of this property
// until after the JRE has completely booted.
// If the sun.nio.cs.map and/or jdk.charset.GB18030 properties are defined
// on the command line we won't see them in the system-properties table until
// after the charset subsystem has been initialized. We therefore delay
// the effect of these property until after the JRE has completely booted.
//
// At the moment following values for this property are supported, property
// value string is case insensitive.
// At the moment the following values for the sun.nio.cs.map property are
// supported and the property value string is case insensitive.
//
// (1)"Windows-31J/Shift_JIS"
// In 1.4.1 we added a correct implementation of the Shift_JIS charset
@ -1176,6 +1177,10 @@ public class ExtendedCharsets
// where each charset named to the left of a slash is intended to replace
// (most) uses of the charset named to the right of the slash.
//
// The jdk.charset.GB18030 property is simpler and accepts only the value
// "2000". If this value is given, the older GB18030-2000 variant of the
// character set replaces the default GB18030-2022 variant.
//
protected void init() {
if (initialized)
return;
@ -1184,6 +1189,8 @@ public class ExtendedCharsets
String map = AccessController.doPrivileged(
new GetPropertyAction("sun.nio.cs.map"));
boolean isGB18030_2000 = "2000".equals(AccessController.doPrivileged(
new GetPropertyAction("jdk.charset.GB18030")));
boolean sjisIsMS932 = false;
boolean iso2022jpIsMS50221 = false;
boolean iso2022jpIsMS50220 = false;
@ -1202,6 +1209,16 @@ public class ExtendedCharsets
}
}
}
if (isGB18030_2000) {
deleteCharset("GB18030",
new String[] {
"gb18030-2022"
});
charset("GB18030", "GB18030",
new String[] {
"gb18030-2000"
});
}
if (sjisIsMS932) {
deleteCharset("Shift_JIS",
new String[] {
@ -1314,6 +1331,7 @@ public class ExtendedCharsets
"x-compound-text"
});
}
this.isGB18030_2000 = isGB18030_2000;
initialized = true;
}
@ -1322,4 +1340,14 @@ public class ExtendedCharsets
return null;
return instance.aliases(charsetName);
}
static boolean IS_2000() {
if (instance == null) {
return false;
}
if (!instance.initialized) {
instance.init();
}
return instance.isGB18030_2000;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, 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
@ -1045,7 +1045,8 @@ public class GB18030
"\u1E26\u1E27\u1E28\u1E29\u1E2A\u1E2B\u1E2C\u1E2D"+
"\u1E2E\u1E2F\u1E30\u1E31\u1E32\u1E33\u1E34\u1E35"+
"\u1E36\u1E37\u1E38\u1E39\u1E3A\u1E3B\u1E3C\u1E3D"+
"\u1E3E\u1E3F\u1E40\u1E41\u1E42\u1E43\u1E44\u1E45"+
(ExtendedCharsets.IS_2000() ? "\u1E3E\u1E3F\u1E40\u1E41\u1E42\u1E43\u1E44\u1E45" :
"\u1E3E\uE7C7\u1E40\u1E41\u1E42\u1E43\u1E44\u1E45")+
"\u1E46\u1E47\u1E48\u1E49\u1E4A\u1E4B\u1E4C\u1E4D"+
"\u1E4E\u1E4F\u1E50\u1E51\u1E52\u1E53\u1E54\u1E55"+
"\u1E56\u1E57\u1E58\u1E59\u1E5A\u1E5B\u1E5C\u1E5D"+
@ -2501,8 +2502,10 @@ public class GB18030
"\u4DF5\u4DF6\u4DF7\u4DF8\u4DF9\u4DFA\u4DFB\u4DFC"+
"\u4DFD\u4DFE\u4DFF\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
(ExtendedCharsets.IS_2000() ? "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" :
"\uFFFD\uE81E\uE826\uE82B\uE82C\uE832\uE843\uE854"+
"\uE864\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD")+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"+
@ -2765,8 +2768,10 @@ public class GB18030
"\uFDF4\uFDF5\uFDF6\uFDF7\uFDF8\uFDF9\uFDFA\uFDFB"+
"\uFDFC\uFDFD\uFDFE\uFDFF\uFE00\uFE01\uFE02\uFE03"+
"\uFE04\uFE05\uFE06\uFE07\uFE08\uFE09\uFE0A\uFE0B"+
"\uFE0C\uFE0D\uFE0E\uFE0F\uFE10\uFE11\uFE12\uFE13"+
"\uFE14\uFE15\uFE16\uFE17\uFE18\uFE19\uFE1A\uFE1B"+
(ExtendedCharsets.IS_2000() ? "\uFE0C\uFE0D\uFE0E\uFE0F\uFE10\uFE11\uFE12\uFE13"+
"\uFE14\uFE15\uFE16\uFE17\uFE18\uFE19\uFE1A\uFE1B" :
"\uFE0C\uFE0D\uFE0E\uFE0F\uE78D\uE78F\uE78E\uE790"+
"\uE791\uE792\uE793\uE794\uE795\uE796\uFE1A\uFE1B")+
"\uFE1C\uFE1D\uFE1E\uFE1F\uFE20\uFE21\uFE22\uFE23"+
"\uFE24\uFE25\uFE26\uFE27\uFE28\uFE29\uFE2A\uFE2B"+
"\uFE2C\uFE2D\uFE2E\uFE2F\uFE32\uFE45\uFE46\uFE47"+
@ -3772,10 +3777,14 @@ public class GB18030
"\uE78A\uE78B\uE78C\u03B1\u03B2\u03B3\u03B4\u03B5"+
"\u03B6\u03B7\u03B8\u03B9\u03BA\u03BB\u03BC\u03BD"+
"\u03BE\u03BF\u03C0\u03C1\u03C3\u03C4\u03C5\u03C6"+
"\u03C7\u03C8\u03C9\uE78D\uE78E\uE78F\uE790\uE791"+
"\uE792\uE793\uFE35\uFE36\uFE39\uFE3A\uFE3F\uFE40"+
"\uFE3D\uFE3E\uFE41\uFE42\uFE43\uFE44\uE794\uE795"+
"\uFE3B\uFE3C\uFE37\uFE38\uFE31\uE796\uFE33\uFE34"+
(ExtendedCharsets.IS_2000() ? "\u03C7\u03C8\u03C9\uE78D\uE78E\uE78F\uE790\uE791"+
"\uE792\uE793\uFE35\uFE36\uFE39\uFE3A\uFE3F\uFE40"+
"\uFE3D\uFE3E\uFE41\uFE42\uFE43\uFE44\uE794\uE795"+
"\uFE3B\uFE3C\uFE37\uFE38\uFE31\uE796\uFE33\uFE34" :
"\u03C7\u03C8\u03C9\uFE10\uFE12\uFE11\uFE13\uFE14"+
"\uFE15\uFE16\uFE35\uFE36\uFE39\uFE3A\uFE3F\uFE40"+
"\uFE3D\uFE3E\uFE41\uFE42\uFE43\uFE44\uFE17\uFE18"+
"\uFE3B\uFE3C\uFE37\uFE38\uFE31\uFE19\uFE33\uFE34")+
"\uE797\uE798\uE799\uE79A\uE79B\uE79C\uE79D\uE79E"+
"\uE79F\uE706\uE707\uE708\uE709\uE70A\uE70B\uE70C"+
"\uE70D\uE70E\uE70F\uE710\uE711\uE712\uE713\uE714"+
@ -3816,7 +3825,8 @@ public class GB18030
"\uE7C6\u0101\u00E1\u01CE\u00E0\u0113\u00E9\u011B"+
"\u00E8\u012B\u00ED\u01D0\u00EC\u014D\u00F3\u01D2"+
"\u00F2\u016B\u00FA\u01D4\u00F9\u01D6\u01D8\u01DA"+
"\u01DC\u00FC\u00EA\u0251\uE7C7\u0144\u0148\u01F9"+
(ExtendedCharsets.IS_2000() ? "\u01DC\u00FC\u00EA\u0251\uE7C7\u0144\u0148\u01F9" :
"\u01DC\u00FC\u00EA\u0251\u1E3F\u0144\u0148\u01F9")+
"\u0261\uE7C9\uE7CA\uE7CB\uE7CC\u3105\u3106\u3107"+
"\u3108\u3109\u310A\u310B\u310C\u310D\u310E\u310F"+
"\u3110\u3111\u3112\u3113\u3114\u3115\u3116\u3117"+
@ -5867,16 +5877,22 @@ public class GB18030
"\uE466\uE467\uFA0C\uFA0D\uFA0E\uFA0F\uFA11\uFA13"+
"\uFA14\uFA18\uFA1F\uFA20\uFA21\uFA23\uFA24\uFA27"+
"\uFA28\uFA29\u2E81\uE816\uE817\uE818\u2E84\u3473"+
"\u3447\u2E88\u2E8B\uE81E\u359E\u361A\u360E\u2E8C"+
"\u2E97\u396E\u3918\uE826\u39CF\u39DF\u3A73\u39D0"+
"\uE82B\uE82C\u3B4E\u3C6E\u3CE0\u2EA7\uE831\uE832"+
(ExtendedCharsets.IS_2000() ? "\u3447\u2E88\u2E8B\uE81E\u359E\u361A\u360E\u2E8C"+
"\u2E97\u396E\u3918\uE826\u39CF\u39DF\u3A73\u39D0"+
"\uE82B\uE82C\u3B4E\u3C6E\u3CE0\u2EA7\uE831\uE832" :
"\u3447\u2E88\u2E8B\u9FB4\u359E\u361A\u360E\u2E8C"+
"\u2E97\u396E\u3918\u9FB5\u39CF\u39DF\u3A73\u39D0"+
"\u9FB6\u9FB7\u3B4E\u3C6E\u3CE0\u2EA7\uE831\u9FB8")+
"\u2EAA\u4056\u415F\u2EAE\u4337\u2EB3\u2EB6\u2EB7"+
"\uE83B\u43B1\u43AC\u2EBB\u43DD\u44D6\u4661\u464C"+
"\uE843\uFFFD\u4723\u4729\u477C\u478D\u2ECA\u4947"+
(ExtendedCharsets.IS_2000() ? "\uE843\uFFFD\u4723\u4729\u477C\u478D\u2ECA\u4947" :
"\u9FB9\uFFFD\u4723\u4729\u477C\u478D\u2ECA\u4947")+
"\u497A\u497D\u4982\u4983\u4985\u4986\u499F\u499B"+
"\u49B7\u49B6\uE854\uE855\u4CA3\u4C9F\u4CA0\u4CA1"+
(ExtendedCharsets.IS_2000() ? "\u49B7\u49B6\uE854\uE855\u4CA3\u4C9F\u4CA0\u4CA1" :
"\u49B7\u49B6\u9FBA\uE855\u4CA3\u4C9F\u4CA0\u4CA1")+
"\u4C77\u4CA2\u4D13\u4D14\u4D15\u4D16\u4D17\u4D18"+
"\u4D19\u4DAE\uE864\uE468\uE469\uE46A\uE46B\uE46C"+
(ExtendedCharsets.IS_2000() ? "\u4D19\u4DAE\uE864\uE468\uE469\uE46A\uE46B\uE46C" :
"\u4D19\u4DAE\u9FBB\uE468\uE469\uE46A\uE46B\uE46C")+
"\uE46D\uE46E\uE46F\uE470\uE471\uE472\uE473\uE474"+
"\uE475\uE476\uE477\uE478\uE479\uE47A\uE47B\uE47C"+
"\uE47D\uE47E\uE47F\uE480\uE481\uE482\uE483\uE484"+
@ -6894,7 +6910,8 @@ public class GB18030
"\u3D02\u3D03\u3D04\u3D05\u3D06\u3D07\u3D08\u3D09"+
"\u3D0A\u3D0B\u3D0C\u3D0D\u3D0E\u3D0F\u3D10\u3D11"+
"\u3D12\u3D13\u3D14\u3D15\u3D16\u3D17\u3D18\u3D19"+
"\u3D1A\u3D1B\u3D1C\u3D1D\u3D1E\u3D1F\u3D20\u3D21"+
(ExtendedCharsets.IS_2000() ? "\u3D1A\u3D1B\u3D1C\u3D1D\u3D1E\u3D1F\u3D20\u3D21" :
"\u3D1A\u3D1B\u3D1C\u3D1D\u3D1E\u3D1F\u3D20\uA8BC")+
"\u3D22\u3D23\u3D24\u3D25\u3D26\u3D27\u3D28\u3D29"+
"\u3D2A\u3D2B\u3D2C\u3D2D\u3D2E\u3D2F\u3D30\u3D31"+
"\u3D32\u3D33\u3D34\u3D35\u3D36\u3D37\u3D38\u3D39"+
@ -11053,8 +11070,10 @@ public class GB18030
"\uFD93\uC1FA\uB9A8\uEDE8\uFD94\uFD95\uFD96\uB9EA"+
"\uD9DF\uFD97\uFD98\uFD99\uFD9A\uFD9B\u6A63\u6A64"+
"\u6A65\u6A66\u6A67\u6A68\u6A69\u6A6A\u6A6B\u6A6C"+
"\u6A6D\u6A6E\u6A6F\u6A70\u6A71\u6A72\u6A73\u6A74"+
"\u6A75\u6A76\u6A77\u6A78\u6A79\u6A7A\u6A7B\u6A7C"+
(ExtendedCharsets.IS_2000() ? "\u6A6D\u6A6E\u6A6F\u6A70\u6A71\u6A72\u6A73\u6A74"+
"\u6A75\u6A76\u6A77\u6A78\u6A79\u6A7A\u6A7B\u6A7C" :
"\u6A6D\u6A6E\u6A6F\u6A70\uFE59\uFE61\uFE66\uFE67"+
"\uFE6D\uFE7E\uFE90\uFEA0\u6A79\u6A7A\u6A7B\u6A7C")+
"\u6A7D\u6A7E\u6A7F\u6A80\u6A81\u6A82\u6A83\u6A84"+
"\u6A85\u6A86\u6A87\u6A88\u6A89\u6A8A\u6A8B\u6A8C"+
"\u6A8D\u6A8E\u6A8F\u6A90\u6A91\u6A92\u6A93\u6A94"+
@ -11466,14 +11485,17 @@ public class GB18030
"\uA2FD\uA2FE\uA4F4\uA4F5\uA4F6\uA4F7\uA4F8\uA4F9"+
"\uA4FA\uA4FB\uA4FC\uA4FD\uA4FE\uA5F7\uA5F8\uA5F9"+
"\uA5FA\uA5FB\uA5FC\uA5FD\uA5FE\uA6B9\uA6BA\uA6BB"+
"\uA6BC\uA6BD\uA6BE\uA6BF\uA6C0\uA6D9\uA6DA\uA6DB"+
"\uA6DC\uA6DD\uA6DE\uA6DF\uA6EC\uA6ED\uA6F3\uA6F6"+
(ExtendedCharsets.IS_2000() ? "\uA6BC\uA6BD\uA6BE\uA6BF\uA6C0\uA6D9\uA6DA\uA6DB"+
"\uA6DC\uA6DD\uA6DE\uA6DF\uA6EC\uA6ED\uA6F3\uA6F6" :
"\uA6BC\uA6BD\uA6BE\uA6BF\uA6C0\u35E7\u35E9\u35E8"+
"\u35EA\u35EB\u35EC\u35ED\u35EE\u35EF\u35F0\uA6F6")+
"\uA6F7\uA6F8\uA6F9\uA6FA\uA6FB\uA6FC\uA6FD\uA6FE"+
"\uA7C2\uA7C3\uA7C4\uA7C5\uA7C6\uA7C7\uA7C8\uA7C9"+
"\uA7CA\uA7CB\uA7CC\uA7CD\uA7CE\uA7CF\uA7D0\uA7F2"+
"\uA7F3\uA7F4\uA7F5\uA7F6\uA7F7\uA7F8\uA7F9\uA7FA"+
"\uA7FB\uA7FC\uA7FD\uA7FE\uA896\uA897\uA898\uA899"+
"\uA89A\uA89B\uA89C\uA89D\uA89E\uA89F\uA8A0\uA8BC"+
(ExtendedCharsets.IS_2000() ? "\uA89A\uA89B\uA89C\uA89D\uA89E\uA89F\uA8A0\uA8BC" :
"\uA89A\uA89B\uA89C\uA89D\uA89E\uA89F\uA8A0\u3D21")+
"\u2001\uA8C1\uA8C2\uA8C3\uA8C4\uA8EA\uA8EB\uA8EC"+
"\uA8ED\uA8EE\uA8EF\uA8F0\uA8F1\uA8F2\uA8F3\uA8F4"+
"\uA8F5\uA8F6\uA8F7\uA8F8\uA8F9\uA8FA\uA8FB\uA8FC"+
@ -11484,16 +11506,23 @@ public class GB18030
"\uA9A3\uA9F0\uA9F1\uA9F2\uA9F3\uA9F4\uA9F5\uA9F6"+
"\uA9F7\uA9F8\uA9F9\uA9FA\uA9FB\uA9FC\uA9FD\uA9FE"+
"\uD7FA\uD7FB\uD7FC\uD7FD\uD7FE\u200F\uFE51\uFE52"+
"\uFE53\u2010\u2011\u2012\u2013\u2014\uFE59\u2015"+
"\u2016\u2017\u2018\u2019\u201A\u201B\uFE61\u201C"+
"\u201D\u201E\u201F\uFE66\uFE67\u2020\u2021\u2022"+
"\u2023\uFE6C\uFE6D\u2024\u2025\u2026\u2027\u2028"+
(ExtendedCharsets.IS_2000() ? "\uFE53\u2010\u2011\u2012\u2013\u2014\uFE59\u2015"+
"\u2016\u2017\u2018\u2019\u201A\u201B\uFE61\u201C"+
"\u201D\u201E\u201F\uFE66\uFE67\u2020\u2021\u2022"+
"\u2023\uFE6C\uFE6D\u2024\u2025\u2026\u2027\u2028" :
"\uFE53\u2010\u2011\u2012\u2013\u2014\u6A71\u2015"+
"\u2016\u2017\u2018\u2019\u201A\u201B\u6A72\u201C"+
"\u201D\u201E\u201F\u6A73\u6A74\u2020\u2021\u2022"+
"\u2023\uFE6C\u6A75\u2024\u2025\u2026\u2027\u2028")+
"\u2029\u202A\u202B\uFE76\u202C\u202D\u202E\u202F"+
"\u2030\u2031\u2032\uFE7E\u2033\u2034\u2035\u2036"+
(ExtendedCharsets.IS_2000() ? "\u2030\u2031\u2032\uFE7E\u2033\u2034\u2035\u2036" :
"\u2030\u2031\u2032\u6A76\u2033\u2034\u2035\u2036")+
"\u2037\u2038\u2039\u203A\u203B\u203C\u203D\u203E"+
"\u203F\u2040\u2041\u2042\uFE90\uFE91\u2043\u2044"+
(ExtendedCharsets.IS_2000() ? "\u203F\u2040\u2041\u2042\uFE90\uFE91\u2043\u2044" :
"\u203F\u2040\u2041\u2042\u6A77\uFE91\u2043\u2044")+
"\u2045\u2046\u2047\u2048\u2049\u204A\u204B\u204C"+
"\u204D\u204E\u204F\u2050\uFEA0\u2051\u2052\u2053"+
(ExtendedCharsets.IS_2000() ? "\u204D\u204E\u204F\u2050\uFEA0\u2051\u2052\u2053" :
"\u204D\u204E\u204F\u2050\u6A78\u2051\u2052\u2053")+
"\u2054\u2055\u2056\u2057\u2058\u2059\u205A\u205B"+
"\u205C\u205D\u205E\u205F\u2060\u2061\u2062\u2063"+
"\u2064\u2065\u2066\u2067\u2068\u2069\u206A\u206B"+
@ -12191,8 +12220,10 @@ public class GB18030
"\u24E3\u24E4\u24E5\u24E6\u24E7\u24E8\u24E9\u24EA"+
"\u24EB\u24EC\u24ED\u24EE\u24EF\u24F0\u24F1\u24F2"+
"\u24F3\u24F4\u24F5\u24F6\u24F7\u24F8\u24F9\u24FA"+
"\u24FB\u24FC\u24FD\u24FE\u24FF\u2500\u2501\u2502"+
"\u2503\u2504\u2505\u2506\u2507\u2508\u2509\u250A"+
(ExtendedCharsets.IS_2000() ? "\u24FB\u24FC\u24FD\u24FE\u24FF\u2500\u2501\u2502"+
"\u2503\u2504\u2505\u2506\u2507\u2508\u2509\u250A" :
"\uA6D9\uA6DB\uA6DA\uA6DC\uA6DD\uA6DE\uA6DF\uA6EC"+
"\uA6ED\uA6F3\u2505\u2506\u2507\u2508\u2509\u250A")+
"\u250B\u250C\u250D\u250E\u250F\u2510\u2511\u2512"+
"\u2513\u2514\u2515\u2516\u2517\u2518\u2519\u251A"+
"\uA955\uA6F2\u251B\uA6F4\uA6F5\uA6E0\uA6E1\uA6F0"+
@ -12341,6 +12372,7 @@ public class GB18030
dp = (dp <= dl ? dp : dl);
int inputSize = 1;
boolean isGB18030_2000 = ExtendedCharsets.IS_2000();
try {
while (sp < sl) {
@ -12409,8 +12441,13 @@ public class GB18030
// BMP Ranges
if (offset <= 0x4A62)
da[dp++] = getChar(offset);
else if (offset > 0x4A62 && offset <= 0x82BC)
da[dp++] = (char)(offset + 0x5543);
else if (offset > 0x4A62 && offset <= 0x82BC) {
if (offset >= 0x4A71 && offset <= 0x4A78 && !isGB18030_2000) {
da[dp++] = getChar(offset);
} else {
da[dp++] = (char)(offset + 0x5543);
}
}
else if (offset >= 0x82BD && offset <= 0x830D)
da[dp++] = getChar(offset);
else if (offset >= 0x830D && offset <= 0x93A8)
@ -12445,7 +12482,7 @@ public class GB18030
CharBuffer dst)
{
int mark = src.position();
boolean isGB18030_2000 = ExtendedCharsets.IS_2000();
try {
while (src.hasRemaining()) {
int byte1 = 0, byte2 = 0, byte3 = 0, byte4 = 0;
@ -12512,8 +12549,13 @@ public class GB18030
// BMP Ranges
if (offset <= 0x4A62)
dst.put(getChar(offset));
else if (offset > 0x4A62 && offset <= 0x82BC)
dst.put((char)(offset + 0x5543));
else if (offset > 0x4A62 && offset <= 0x82BC) {
if (offset >= 0x4A71 && offset <= 0x4A78 && !isGB18030_2000) {
dst.put(getChar(offset));
} else {
dst.put((char)(offset + 0x5543));
}
}
else if (offset >= 0x82BD && offset <= 0x830D)
dst.put(getChar(offset));
else if (offset >= 0x830D && offset <= 0x93A8)
@ -12595,6 +12637,7 @@ public class GB18030
int condensedKey = 0; // expands to a four byte sequence
int hiByte = 0, loByte = 0;
currentState = GB18030_DOUBLE_BYTE;
boolean isGB18030_2000 = ExtendedCharsets.IS_2000();
try {
while (sp < sl) {
@ -12626,15 +12669,33 @@ public class GB18030
condensedKey = (hiByte - 0x20) * 256 + loByte;
if (c >= 0xE000 && c < 0xF900)
if (c >= 0xE000 && c < 0xF900) {
if (isGB18030_2000) {
condensedKey += 0x82BD;
} else {
switch (c) {
case 0xE7C7:
case 0xE81E:
case 0xE826:
case 0xE82B:
case 0xE82C:
case 0xE832:
case 0xE843:
case 0xE854:
case 0xE864:
break;
default:
condensedKey += 0x82BD;
};
}
}
else if (c >= 0xF900)
condensedKey += 0x93A9;
condensedKey += 0x93A9;
if (hiByte > 0x80)
currentState = GB18030_DOUBLE_BYTE;
currentState = GB18030_DOUBLE_BYTE;
else
currentState = GB18030_FOUR_BYTE;
currentState = GB18030_FOUR_BYTE;
}
else if (c >= 0xA4C7 && c <= 0xD7FF) {
condensedKey = c - 0x5543;
@ -12677,7 +12738,7 @@ public class GB18030
}
sp += inputSize;
}
return CoderResult.UNDERFLOW;
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
@ -12691,6 +12752,7 @@ public class GB18030
int hiByte = 0, loByte = 0;
currentState = GB18030_DOUBLE_BYTE;
int mark = src.position();
boolean isGB18030_2000 = ExtendedCharsets.IS_2000();
try {
while (src.hasRemaining()) {
char c = src.get();
@ -12717,15 +12779,33 @@ public class GB18030
condensedKey = (hiByte - 0x20) * 256 + loByte;
if (c >= 0xE000 && c < 0xF900)
if (c >= 0xE000 && c < 0xF900) {
if (isGB18030_2000) {
condensedKey += 0x82BD;
} else {
switch (c) {
case 0xE7C7:
case 0xE81E:
case 0xE826:
case 0xE82B:
case 0xE82C:
case 0xE832:
case 0xE843:
case 0xE854:
case 0xE864:
break;
default:
condensedKey += 0x82BD;
};
}
}
else if (c >= 0xF900)
condensedKey += 0x93A9;
condensedKey += 0x93A9;
if (hiByte > 0x80)
currentState = GB18030_DOUBLE_BYTE;
currentState = GB18030_DOUBLE_BYTE;
else
currentState = GB18030_FOUR_BYTE;
currentState = GB18030_FOUR_BYTE;
}
else if (c >= 0xA4C7 && c <= 0xD7FF) {
condensedKey = c - 0x5543;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023, 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
@ -22,8 +22,11 @@
*/
/* @test
* @bug 4473201 4696726 4652234 4482298 4784385 4966197 4267354 5015668 6911753
* @bug 4473201 4696726 4652234 4482298 4784385 4966197 4267354 5015668
6911753 8071447 8301119
* @summary Check that registered charsets are actually registered
* @run main RegisteredCharsets
* @run main/othervm -Djdk.charset.GB18030=2000 RegisteredCharsets
*/
import java.io.*;
@ -250,8 +253,12 @@ public class RegisteredCharsets {
});
aliasCheck("GB18030",
"2000".equals(System.getProperty("jdk.charset.GB18030")) ?
new String[] {
"gb18030-2000"
} :
new String[] {
"gb18030-2022"
});
aliasCheck("ISO-2022-KR", new String[] {"csISO2022KR"});

View File

@ -34,17 +34,20 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Set;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.util.Collections;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.concurrent.TimeUnit;
@ -464,4 +467,728 @@ public final class Utils {
Path dir = Paths.get(System.getProperty("user.dir", "."));
return Files.createTempDirectory(dir, prefix);
}
/*
List.of implementations
These methods are intended to provide replacements
for the use of List.of() methods in backports,
using existing 8u methods. The returned collections
share the key property of the List.of collections
in being unmodifiable, but may not be equivalent
with regard to other properties such as serialization
and access order.
*/
/**
* Returns an unmodifiable list containing zero elements.
*
* @param <E> the {@code List}'s element type
* @return an empty {@code List}
*/
public static <E> List<E> listOf() {
return Collections.emptyList();
}
/**
* Returns an unmodifiable list containing one element.
*
* @param <E> the {@code List}'s element type
* @param e1 the single element
* @return a {@code List} containing the specified element
* @throws NullPointerException if the element is {@code null}
*/
public static <E> List<E> listOf(E e1) {
Objects.requireNonNull(e1, "e1");
return Collections.singletonList(e1);
}
/**
* Returns an unmodifiable list containing two elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
List<E> l = new ArrayList<>(2);
l.add(e1);
l.add(e2);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing three elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
List<E> l = new ArrayList<>(3);
l.add(e1);
l.add(e2);
l.add(e3);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing four elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
List<E> l = new ArrayList<>(4);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing five elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4, E e5) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
List<E> l = new ArrayList<>(5);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
l.add(e5);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing six elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4, E e5, E e6) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
List<E> l = new ArrayList<>(6);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
l.add(e5);
l.add(e6);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing seven elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
List<E> l = new ArrayList<>(7);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
l.add(e5);
l.add(e6);
l.add(e7);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing eight elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @param e8 the eighth element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Objects.requireNonNull(e8, "e8");
List<E> l = new ArrayList<>(8);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
l.add(e5);
l.add(e6);
l.add(e7);
l.add(e8);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing nine elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @param e8 the eighth element
* @param e9 the ninth element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Objects.requireNonNull(e8, "e8");
Objects.requireNonNull(e9, "e9");
List<E> l = new ArrayList<>(9);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
l.add(e5);
l.add(e6);
l.add(e7);
l.add(e8);
l.add(e9);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing ten elements.
*
* @param <E> the {@code List}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @param e8 the eighth element
* @param e9 the ninth element
* @param e10 the tenth element
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> List<E> listOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Objects.requireNonNull(e8, "e8");
Objects.requireNonNull(e9, "e9");
Objects.requireNonNull(e10, "e10");
List<E> l = new ArrayList<>(10);
l.add(e1);
l.add(e2);
l.add(e3);
l.add(e4);
l.add(e5);
l.add(e6);
l.add(e7);
l.add(e8);
l.add(e9);
l.add(e10);
return Collections.unmodifiableList(l);
}
/**
* Returns an unmodifiable list containing an arbitrary number of elements.
*
* @apiNote
* This method also accepts a single array as an argument. The element type of
* the resulting list will be the component type of the array, and the size of
* the list will be equal to the length of the array. To create a list with
* a single element that is an array, do the following:
*
* <pre>{@code
* String[] array = ... ;
* List<String[]> list = Utils.<String[]>listOf(array);
* }</pre>
*
* This will cause the {@link Utils#listOf(Object) listOf(E)} method
* to be invoked instead.
*
* @param <E> the {@code List}'s element type
* @param elements the elements to be contained in the list
* @return a {@code List} containing the specified elements
* @throws NullPointerException if an element is {@code null} or if the array is {@code null}
*/
@SafeVarargs
@SuppressWarnings("varargs")
public static <E> List<E> listOf(E... elements) {
switch (elements.length) { // implicit null check of elements
case 0:
return listOf();
case 1:
return listOf(elements[0]);
case 2:
return listOf(elements[0], elements[1]);
default:
for (int a = 0; a < elements.length; ++a) {
Objects.requireNonNull(elements[a], "e" + a);
}
return Collections.unmodifiableList(Arrays.asList(elements));
}
}
/*
Set.of implementations
These methods are intended to provide replacements
for the use of Set.of() methods in backports,
using existing 8u methods. The returned collections
share the key property of the Set.of collections
in being unmodifiable, but may not be equivalent
with regard to other properties such as serialization
and access order.
*/
/**
* Returns an unmodifiable set containing zero elements.
*
* @param <E> the {@code Set}'s element type
* @return an empty {@code Set}
*/
public static <E> Set<E> setOf() {
return Collections.emptySet();
}
/**
* Returns an unmodifiable set containing one element.
*
* @param <E> the {@code Set}'s element type
* @param e1 the single element
* @return a {@code Set} containing the specified element
* @throws NullPointerException if the element is {@code null}
*/
public static <E> Set<E> setOf(E e1) {
Objects.requireNonNull(e1, "e1");
Set<E> s = new HashSet<>(1);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing two elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if the elements are duplicates
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Set<E> s = new HashSet<>(2);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing three elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing four elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing five elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4, E e5) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
if (!s.add(e5)) { throw new IllegalArgumentException("duplicate 5"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing six elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4, E e5, E e6) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
if (!s.add(e5)) { throw new IllegalArgumentException("duplicate 5"); }
if (!s.add(e6)) { throw new IllegalArgumentException("duplicate 6"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing seven elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
if (!s.add(e5)) { throw new IllegalArgumentException("duplicate 5"); }
if (!s.add(e6)) { throw new IllegalArgumentException("duplicate 6"); }
if (!s.add(e7)) { throw new IllegalArgumentException("duplicate 7"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing eight elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @param e8 the eighth element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Objects.requireNonNull(e8, "e8");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
if (!s.add(e5)) { throw new IllegalArgumentException("duplicate 5"); }
if (!s.add(e6)) { throw new IllegalArgumentException("duplicate 6"); }
if (!s.add(e7)) { throw new IllegalArgumentException("duplicate 7"); }
if (!s.add(e8)) { throw new IllegalArgumentException("duplicate 8"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing nine elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @param e8 the eighth element
* @param e9 the ninth element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Objects.requireNonNull(e8, "e8");
Objects.requireNonNull(e9, "e9");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
if (!s.add(e5)) { throw new IllegalArgumentException("duplicate 5"); }
if (!s.add(e6)) { throw new IllegalArgumentException("duplicate 6"); }
if (!s.add(e7)) { throw new IllegalArgumentException("duplicate 7"); }
if (!s.add(e8)) { throw new IllegalArgumentException("duplicate 8"); }
if (!s.add(e9)) { throw new IllegalArgumentException("duplicate 9"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing ten elements.
*
* @param <E> the {@code Set}'s element type
* @param e1 the first element
* @param e2 the second element
* @param e3 the third element
* @param e4 the fourth element
* @param e5 the fifth element
* @param e6 the sixth element
* @param e7 the seventh element
* @param e8 the eighth element
* @param e9 the ninth element
* @param e10 the tenth element
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null}
*/
public static <E> Set<E> setOf(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) {
Objects.requireNonNull(e1, "e1");
Objects.requireNonNull(e2, "e2");
Objects.requireNonNull(e3, "e3");
Objects.requireNonNull(e4, "e4");
Objects.requireNonNull(e5, "e5");
Objects.requireNonNull(e6, "e6");
Objects.requireNonNull(e7, "e7");
Objects.requireNonNull(e8, "e8");
Objects.requireNonNull(e9, "e9");
Objects.requireNonNull(e10, "e10");
Set<E> s = new HashSet<>(10);
if (!s.add(e1)) { throw new IllegalArgumentException("duplicate 1"); }
if (!s.add(e2)) { throw new IllegalArgumentException("duplicate 2"); }
if (!s.add(e3)) { throw new IllegalArgumentException("duplicate 3"); }
if (!s.add(e4)) { throw new IllegalArgumentException("duplicate 4"); }
if (!s.add(e5)) { throw new IllegalArgumentException("duplicate 5"); }
if (!s.add(e6)) { throw new IllegalArgumentException("duplicate 6"); }
if (!s.add(e7)) { throw new IllegalArgumentException("duplicate 7"); }
if (!s.add(e8)) { throw new IllegalArgumentException("duplicate 8"); }
if (!s.add(e9)) { throw new IllegalArgumentException("duplicate 9"); }
if (!s.add(e10)) { throw new IllegalArgumentException("duplicate 10"); }
return Collections.unmodifiableSet(s);
}
/**
* Returns an unmodifiable set containing an arbitrary number of elements.
*
* @apiNote
* This method also accepts a single array as an argument. The element type of
* the resulting set will be the component type of the array, and the size of
* the set will be equal to the length of the array. To create a set with
* a single element that is an array, do the following:
*
* <pre>{@code
* String[] array = ... ;
* Set<String[]> list = Utils.<String[]>setOf(array);
* }</pre>
*
* This will cause the {@link Utils#setOf(Object) Utils.setOf(E)} method
* to be invoked instead.
*
* @param <E> the {@code Set}'s element type
* @param elements the elements to be contained in the set
* @return a {@code Set} containing the specified elements
* @throws IllegalArgumentException if there are any duplicate elements
* @throws NullPointerException if an element is {@code null} or if the array is {@code null}
*/
@SafeVarargs
@SuppressWarnings("varargs")
public static <E> Set<E> setOf(E... elements) {
switch (elements.length) { // implicit null check of elements
case 0:
return setOf();
case 1:
return setOf(elements[0]);
case 2:
return setOf(elements[1]);
default:
Set<E> s = new HashSet<>(elements.length);
for (int a = 0; a < elements.length; ++a) {
Objects.requireNonNull(elements[a], "e" + a);
if (!s.add(elements[a])) {
throw new IllegalArgumentException("duplicate " + a);
}
}
return Collections.unmodifiableSet(s);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -22,20 +22,24 @@
*/
/* @test
* @bug 8211382
* @bug 8211382 8301119
* @summary Check GB18030
* @modules jdk.charsets
* @library /lib/testlibrary
* @build jdk.testlibrary.Utils
* @run main TestGB18030
* @run main/othervm -Djdk.charset.GB18030=2000 TestGB18030
*/
import java.io.*;
import java.nio.*;
import java.nio.charset.*;
import java.util.Set;
import jdk.testlibrary.Utils;
public class TestGB18030 {
private static final Charset cs = Charset.forName("GB18030");
public static void gb18030_1(boolean useDirect) throws Exception {
for(char ch : new char[]{'\uFFFE', '\uFFFF'}) {
char[] ca = new char[]{ch};
Charset cs = Charset.forName("GB18030");
CharsetEncoder ce = cs.newEncoder();
CharsetDecoder cd = cs.newDecoder();
CharBuffer cb = CharBuffer.wrap(ca);
@ -75,8 +79,19 @@ public class TestGB18030 {
}
}
}
static void checkAlias() {
boolean IS_2000 = "2000".equals(System.getProperty("jdk.charset.GB18030"));
Set<String> expected = IS_2000 ? Utils.setOf("gb18030-2000") : Utils.setOf("gb18030-2022");
Set<String> found = cs.aliases();
System.out.printf("checkAlias(): IS_2000: %s, expected: %s, found: %s\n", IS_2000, expected, found);
if (!cs.aliases().equals(expected)) {
throw new RuntimeException("Result mismatch");
}
}
public static void main(String args[]) throws Exception {
gb18030_1(false);
gb18030_1(true);
checkAlias();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
@ -22,8 +22,10 @@
*/
/* @test
@bug 4691554 6221056 6380723 6404504 6419565 6529796
@bug 4691554 6221056 6380723 6404504 6419565 6529796 8301119
@summary Test the supported New I/O coders
@run main CoderTest
@run main/othervm -Djdk.charset.GB18030=2000 CoderTest
*/
import java.io.*;
@ -55,6 +57,9 @@ public class CoderTest {
".c2b-irreversible",
".b2c-irreversible" };
private static final boolean IS_2000 =
"2000".equals(System.getProperty("jdk.charset.GB18030"));
// Utilities
private static ByteBuffer expand(ByteBuffer bb) {
@ -465,7 +470,12 @@ public class CoderTest {
// Outer loop runs three passes: roundtrip, irreversible encodings,
// and then irreversible decodings
for (int mode = ROUNDTRIP; mode <= DECODE; mode++) {
File f = testFile(encoding, mode);
String fileName = encoding;
if (fileName.equals("GB18030") && IS_2000) {
// tweak the map file name
fileName = "GB18030_2000";
}
File f = testFile(fileName, mode);
if (f == null)
continue;
loadTests(f);

View File

@ -1,3 +1,4 @@
# based on GB18030-2022 mapping
00 0000
01 0001
02 0002
@ -7741,7 +7742,7 @@ A7D7 0451
8135F434 1E3C
8135F435 1E3D
8135F436 1E3E
8135F437 1E3F
A8BC 1E3F
8135F438 1E40
8135F439 1E41
8135F530 1E42
@ -40882,14 +40883,14 @@ FD9B 9FA5
82359034 9FB1
82359035 9FB2
82359036 9FB3
82359037 9FB4
82359038 9FB5
82359039 9FB6
82359130 9FB7
82359131 9FB8
82359132 9FB9
82359133 9FBA
82359134 9FBB
82359037 E81E
82359038 E826
82359039 E82B
82359130 E82C
82359131 E832
82359132 E843
82359133 E854
82359134 E864
82359135 9FBC
82359136 9FBD
82359137 9FBE
@ -57227,16 +57228,16 @@ A6BD E789
A6BE E78A
A6BF E78B
A6C0 E78C
A6D9 E78D
A6DA E78E
A6DB E78F
A6DC E790
A6DD E791
A6DE E792
A6DF E793
A6EC E794
A6ED E795
A6F3 E796
A6D9 FE10
A6DA FE12
A6DB FE11
A6DC FE13
A6DD FE14
A6DE FE15
A6DF FE16
A6EC FE17
A6ED FE18
A6F3 FE19
A6F6 E797
A6F7 E798
A6F8 E799
@ -57285,7 +57286,7 @@ A89D E7C3
A89E E7C4
A89F E7C5
A8A0 E7C6
A8BC E7C7
8135F437 E7C7
8336C830 E7C8
A8C1 E7C9
A8C2 E7CA
@ -57372,7 +57373,7 @@ FE53 E818
8336C937 E81B
8336C938 E81C
8336C939 E81D
FE59 E81E
FE59 9FB4
8336CA30 E81F
8336CA31 E820
8336CA32 E821
@ -57380,19 +57381,19 @@ FE59 E81E
8336CA34 E823
8336CA35 E824
8336CA36 E825
FE61 E826
FE61 9FB5
8336CA37 E827
8336CA38 E828
8336CA39 E829
8336CB30 E82A
FE66 E82B
FE67 E82C
FE66 9FB6
FE67 9FB7
8336CB31 E82D
8336CB32 E82E
8336CB33 E82F
8336CB34 E830
FE6C E831
FE6D E832
FE6D 9FB8
8336CB35 E833
8336CB36 E834
8336CB37 E835
@ -57409,7 +57410,7 @@ FE76 E83B
8336CC37 E840
8336CC38 E841
8336CC39 E842
FE7E E843
FE7E 9FB9
8336CD30 E844
8336CD31 E845
8336CD32 E846
@ -57426,7 +57427,7 @@ FE7E E843
8336CE33 E851
8336CE34 E852
8336CE35 E853
FE90 E854
FE90 9FBA
FE91 E855
8336CE36 E856
8336CE37 E857
@ -57442,7 +57443,7 @@ FE91 E855
8336CF37 E861
8336CF38 E862
8336CF39 E863
FEA0 E864
FEA0 9FBB
8336D030 E865
8336D031 E866
8336D032 E867
@ -62990,16 +62991,16 @@ FE4F FA29
84318233 FE0D
84318234 FE0E
84318235 FE0F
84318236 FE10
84318237 FE11
84318238 FE12
84318239 FE13
84318330 FE14
84318331 FE15
84318332 FE16
84318333 FE17
84318334 FE18
84318335 FE19
84318236 E78D
84318237 E78F
84318238 E78E
84318239 E790
84318330 E791
84318331 E792
84318332 E793
84318333 E794
84318334 E795
84318335 E796
84318336 FE1A
84318337 FE1B
84318338 FE1C
@ -63484,5 +63485,5 @@ A3A4 FFE5
8431A435 FFFB
8431A436 FFFC
8431A437 FFFD
#8431A438 FFFE
#8431A439 FFFF
8431A438 FFFE
8431A439 FFFF

View File

@ -1,6 +1,4 @@
# GB18030.java is NOT generated from this mapping right now. This
# map is here for testing only.
#
# based on GB18030-2000 mapping
00 0000
01 0001
02 0002