On Sat, 15 Aug 2026 09:47:46 GMT, Markus KARG <[email protected]> wrote:

>> src/java.base/share/classes/sun/nio/cs/StreamDecoder.java line 211:
>> 
>>> 209: 
>>> 210:             if (!havePulledFromInputStream)
>>> 211:                 return new String(remaining, cs);
>> 
>> This assumes the CharsetDecoder is configured to use REPLACE. You'll see to 
>> look at the uses of StreamDecoder where it may be created with a 
>> CharsetDecoder configured otherwise (e.g. InputStreamReader constructor that 
>> is created with a CharsetDecoder).
>
> I have now added a check that will execute the fast-path optimization only in 
> the REPLACE case, and only with the very same charset decoder class.

I don't think this is quite right. A CharsetDecoder can be configured with a 
"replacement value" so it may be different than the default. If someone creates 
an InputStreamDecoder with a configured CharsetDecoder then the proposed fast 
path will use the String constructor and the default replacement value, oops!

The slow path looks like it has an issue too. The decoder needs to be reset at 
EOF, otherwise a subsequent read will throw rather than return -1. Look at the 
existing implRead implementation to see what I mean.

It might be simpler to reduce the focus of the proposal to only the cases where 
an InputStreamReader is created with a Charset and no characters are reader 
from the reader before readAsString is invoked to consume to EOF. Leave all 
other cases to the existing code.

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

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

Reply via email to