Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jdk/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Locale;
import java.util.Map;
import sun.misc.ASCIICaseInsensitiveComparator;

import sun.nio.cs.ext.GB18030;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on GB18030 class (sun.nio.cs.ext. in charsets.jar) in package sun.nio.cs (rt.jar) seems worrisome.


/**
* Abstract base class for charset providers.
Expand Down Expand Up @@ -115,9 +115,14 @@ protected void deleteCharset(String name, String[] aliases) {
*/
protected void init() { }

private String canonicalize(String charsetName) {
String acn = aliasMap.get(charsetName);
return (acn != null) ? acn : charsetName;
private String canonicalize(String csn) {
if (csn.startsWith("gb18030-")) {
return csn.equals("gb18030-2022") && !GB18030.IS_2000 ||
csn.equals("gb18030-2000") && GB18030.IS_2000 ? "gb18030" : csn;
} else {
String acn = aliasMap.get(csn);
return (acn != null) ? acn : csn;
}
Comment on lines +118 to +125
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if we hooked into the late initialization hook instead we wouldn't need this canonicalization as the aliasMap would map it back to the correct class name.

}

private Charset lookup(String csn) {
Expand Down
7 changes: 2 additions & 5 deletions jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,9 +25,6 @@

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;
Expand Down Expand Up @@ -117,7 +114,7 @@ public ExtendedCharsets() {

charset("GB18030", "GB18030",
new String[] {
"gb18030-2000"
GB18030.IS_2000 ? "gb18030-2000" : "gb18030-2022"
Comment on lines 115 to +117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initialization will be wrong when run with LANG=zh_CN.GB18030 and -Djdk.charset.GB18030=2000as in that case the GB18030.IS_2000 will be false as the JVM won't have properly initialized yet. Again a suggestion to use the late init hook instead. See https://bugs.openjdk.org/browse/JDK-8310947

});

charset("GB2312", "EUC_CN",
Expand Down
175 changes: 130 additions & 45 deletions jdk/src/share/classes/sun/nio/cs/ext/GB18030.java

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions jdk/test/java/nio/charset/Charset/RegisteredCharsets.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.*;
Expand Down Expand Up @@ -250,8 +253,12 @@ public static void main(String[] args) throws Exception {
});

aliasCheck("GB18030",
"2000".equals(System.getProperty("jdk.charset.GB18030")) ?
new String[] {
"gb18030-2000"
} :
new String[] {
"gb18030-2022"
});

aliasCheck("ISO-2022-KR", new String[] {"csISO2022KR"});
Expand Down
Loading