On Sat, 8 Aug 2026 15:56:55 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).

src/java.base/share/classes/sun/nio/cs/StreamDecoder.java line 52:

> 50:     private static final int DEFAULT_BYTE_BUFFER_SIZE = 8192;
> 51: 
> 52:     private volatile boolean havePulledFromInputStream;

If this patch goes ahead then we'll need a better name for this. But first, why 
it is volatile. The reason that closed is volatile is because of async close.

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.

src/java.base/share/classes/sun/nio/cs/StreamDecoder.java line 213:

> 211:                 return new String(remaining, cs);
> 212: 
> 213:             int estimateSize = (haveLeftoverChar ? 1 : 0) + (int) 
> Math.ceil((bb.remaining() + remaining.length) * decoder.maxCharsPerByte());

You can reformat this to be more consistent with the existing code.

src/java.base/share/classes/sun/nio/cs/StreamDecoder.java line 239:

> 237:             }
> 238: 
> 239:             return cb.flip().toString();

Have you tested this with underflow? From a quick loop I can't tell if this 
will go into an infinite loop or leave unconsumed chars.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32264#discussion_r3741102351
PR Review Comment: https://git.openjdk.org/jdk/pull/32264#discussion_r3741081781
PR Review Comment: https://git.openjdk.org/jdk/pull/32264#discussion_r3741101273
PR Review Comment: https://git.openjdk.org/jdk/pull/32264#discussion_r3741100767

Reply via email to