On Thu, 27 Aug 2026 16:55:36 GMT, Jaikiran Pai <[email protected]> wrote:

>> Markus KARG has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Simplified approach by Alan Bateman
>
> 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.

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

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

Reply via email to