On Tue, 25 Aug 2026 17:46:19 GMT, Markus KARG <[email protected]> wrote:

>> This Pull Request provides an implementation for 
>> [JDK-8389573](https://bugs.openjdk.org/browse/JDK-8389573): 
>> 'InputStreamReader.readAllAsString() should override the generic Reader 
>> default implementation to avoid unnecessary buffer copies'.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> 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`?

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

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

Reply via email to