RFR: 8371718: (sc) Channels.new{Input, Output}Stream can allocate unbounded memory for a socket channel [v4]

Alan Bateman alanb at openjdk.org
Tue Dec 9 17:49:54 UTC 2025


On Tue, 9 Dec 2025 17:09:36 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Clamp read and write to 128k bytes.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8371718: Address reviewer comments v2

src/java.base/share/classes/sun/nio/ch/ChannelOutputStream.java line 73:

> 71:             int n = ch.write(bb);
> 72:             if (n <= 0)
> 73:                 throw new IOException("Write failed");

It would be a broken WritableByteChannel implementation to return < 0. If it were a non-blocking then IllegalBlockingModeException would be thrown already. So I think this throw IOException is okay here but it is a sign of a broken channel implementation.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28705#discussion_r2603667396


More information about the nio-dev mailing list