RFR: 8316156: ByteArrayInputStream.transferTo causes MaxDirectMemorySize overflow [v6]
zde
duke at openjdk.org
Fri Mar 15 13:30:07 UTC 2024
On Tue, 19 Sep 2023 20:03:57 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> `ByteArrayInputStream.transferTo` invoked with an `OutputStream` parameter which delegates to a `FileChannel` throws an `OutOfMemoryError` if the length of the `byte[]` wrapped by the `ByteArrayInputStream` exceeds `MaxDirectMemorySize`. This is because `FileChannel.write` uses `IOUtil.write` which creates a temporary direct buffer for writing. If the `byte[]` length is larger than `MaxDirectMemorySize`, then the temporary direct buffer allocation fails with an `OutOfMemoryError`.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>
> 8316156: Revert BufferedInputStream changes; update test
> because FileChannel.write uses IOUtil.write which creates a temporary direct buffer for writing
Why are you "fixing" `ByteArrayInputStream.writeTo` when the problem is elsewhere?
`IOUtil.write` should create a reasonably sized buffer and reuse it instead.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15733#issuecomment-1999658309
More information about the nio-dev
mailing list