RFR: 8305902: (cs) Resolve default Charset only once in StreamEncoder and StreamDecoder

Alan Bateman alanb at openjdk.org
Wed Apr 12 12:28:33 UTC 2023


On Wed, 12 Apr 2023 12:17:28 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:

>> src/java.base/share/classes/sun/nio/cs/StreamDecoder.java line 76:
>> 
>>> 74:         String csn = charsetName;
>>> 75:         try {
>>> 76:             return new StreamDecoder(in, lock, csn == null ? Charset.defaultCharset() : Charset.forName(csn));
>> 
>> Can you check the callers, it may be that the mapping of null to the default CS can be removed.
>
> The callers throw NPE in case of null csName, but both are Encoder and Decoder are public. Will it be safe to remove explicit null check?

sun.nio.cs is a JDK internal package. The only usages of StreamDecoder.forInputStreamReader and StreamEncoder.forOutputStreamWriter. You should be able to quickly check the usages.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13443#discussion_r1164059360


More information about the nio-dev mailing list