On Thu, 27 Aug 2026 21:46:52 GMT, Chen Liang <[email protected]> wrote:

>> src/java.base/share/classes/sun/nio/cs/StreamDecoder.java line 252:
>> 
>>> 250: 
>>> 251:     StreamDecoder(InputStream in, Object lock, CharsetDecoder dec) {
>>> 252:         this(in, lock, dec.charset(), dec, false);
>> 
>> Hello Markus, from what I see in the specification of the (protected) 
>> constructor `java.nio.charset.CharsetDecoder` and its `charset()` method 
>> which returns the `Charset`, neither of those specify that `null` is 
>> disallowed for `Charset`. In fact, a trivial example shows that no 
>> exceptions get thrown for `null` `Charset` for the `CharsetDecoder`. Given 
>> this, it's possible that the `Charset` obtained from `CharsetDecoder` could 
>> be `null`.
>> 
>> The `StreamDecoder` already (even without the proposed changes) has a few 
>> places where it will run into a NullPointerException, if the Charset is 
>> null. With the new proposed change, when constructing a `String` in 
>> `tryReadAllAsString()` that can now lead to a `NullPointerException` and 
>> propagate out of the `InputStreamReader.readAllAsString()` call.
>> 
>> Perhaps we should enforce non-null `Charset` when constructing the 
>> `StreamDecoder`?
>
> Good call, but I think this best belongs to a separate enhancement or bug.

InputStreamReader checks for nulls at the "front door", in its constructors 
before creating the StreamDecoder. A separate JBS issue to track updating the 
ISR constructor to specify these NPEs would be good.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32264#discussion_r3879981175

Reply via email to