[External] : Re: InputStream/OutputStream concurrency guarantees
Viktor Klang
viktor.klang at oracle.com
Thu Oct 30 17:25:48 UTC 2025
The creation of said signatures was most likely to reduce copying of
buffers so copying the buffer would likely be going against the design.
Presumably the party which passes the array to the read/write is in
control of said array, so if one wants to defensively copy it before
passing it to the read/write it is definitely possible to do so on a
case-by-case basis.
One important difference to something like String is that String is
immutable, so being able to create a mutable String would subvert the
guarantees of the type—the same is not the case for
InputStream/OutputStream.
On 2025-10-30 18:10, Florian Weimer wrote:
> * Viktor Klang:
>
>> Also, since there aren't any consistency effects in place, it is not
>> deterministic which changes made by the writer would be seen by the
>> reader/copier.
> Sure, but if a defensive copy were made, at least the output would be
> internally consistent. This would be similar to what various
> byte[]-accepting String methods already do.
>
> But it seems to me that the consensus seems to be that
> InputStream/OutputStream do not need to do this, and (for example)
> FileInputStream and FileOutputStream could be changed in ways that make
> multiple byte array reads and writes observable through race conditions.
>
> Thanks,
> Florian
>
--
Cheers,
√
Viktor Klang
Software Architect, Java Platform Group
Oracle
More information about the core-libs-dev
mailing list