RFR: 8265891: (ch) InputStream returned by Channels.newInputStream should override transferTo [v6]
Markus KARG
github.com+1701815+mkarg at openjdk.java.net
Thu Jul 29 08:15:32 UTC 2021
On Mon, 26 Jul 2021 23:59:05 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> Markus KARG has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR.
>
> src/java.base/share/classes/sun/nio/ch/ChannelInputStream.java line 179:
>
>> 177: for (long n = srcSize - srcPos; bytesWritten < n;)
>> 178: bytesWritten += src.transferTo(srcPos + bytesWritten, Long.MAX_VALUE, dest);
>> 179: return bytesWritten;
>
> If `src` is extended at an inconvenient point in time, for example between the return from a call to `src.transferTo()` that makes `bytesWritten < n` false and the evaluation of that terminating condition, then it appears that not all the content of `src` will be transferred to `dest`. I am not however sure that this violates any contract but it could be a behavioral change from the existing implementation.
The JavaDocs in `InputStream::transferTo` *cleary* tell the caller that there is **no** guarantee of *any* specific behavior in that particular case:
>The behavior for the case where the input and/or output stream is asynchronously closed, or the thread interrupted during the transfer, is highly input and output stream specific, and therefore not specified.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4263
More information about the nio-dev
mailing list