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

Sergey Tsypanov stsypanov at openjdk.org
Wed Apr 12 12:20:33 UTC 2023


On Wed, 12 Apr 2023 11:41:39 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> If `charsetName` passed into `forOutputStreamWriter()` method is null then `Charset.forName()` is redundant as we can use already resolved default Charset.
>
> 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?

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

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


More information about the nio-dev mailing list