RFR: 8306308: (ch) Writer created by Channels::newWriter may lose data [v2]

Alan Bateman alanb at openjdk.org
Wed Oct 18 14:46:03 UTC 2023


On Wed, 18 Oct 2023 01:01:27 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Change `Channels.newWriter` to return a `Writer` created by first wrapping the `WritableByteChannel` in an `OutputStream` using `Channels.newOutputStream` and then wrapping the result in an `OutputStreamWriter`. With this change in place, the problems reported in the issue do not occur.
>
> Brian Burkhalter has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - 8306308: Remove WritableByteChannel support from StreamEncoder
>  - 8306308: new OutputStreamWriter -> StreamEncoder.forOutputStreamWriter

src/java.base/share/classes/java/nio/channels/Channels.java line 546:

> 544:         Objects.requireNonNull(enc, "enc");
> 545:         return StreamEncoder.forOutputStreamWriter(newOutputStream(ch),
> 546:             new Object(), enc.reset());

I'm not sure about this lock Object, you may have to add a 2-arg forOutputstreamWriter so that the no-arg Writer is used.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16207#discussion_r1364012165


More information about the nio-dev mailing list