8220477: Channels.newWriter() does not close if underlying channel throws an IOException
Alan Bateman
Alan.Bateman at oracle.com
Fri Apr 12 07:18:46 UTC 2019
On 11/04/2019 22:36, Brian Burkhalter wrote:
>
> Revisiting the failure mentioned above, it turns out that this is
> because a StreamEncoder for an OutputStream does not flush the stream
> before closing it. It seems like it should. (I don’t know whether this
> should perhaps be the subject of a separate issue.) The webrev [1] for
> the current issue 8220477 is updated to do this. The difference versus
> the previous webrev is [2]. It might be overkill to handle the
> IOException from OutputStream.flush() instead of just ignoring it, I’m
> not sure.
>
It seems reasonable but it adds complexity to prefer the exception from
flush over the close. The alternative is the much simpler:
try {
out.flush();
} finally {
out.close();
}
As always, if the flush fails then it's possible that the close will
attempt to flush again so there may be several suppressed exceptions.
-Alan
More information about the nio-dev
mailing list