RFR: 8136895: Writer not closed with disk full error, file resource leaked
Brian Burkhalter
bpb at openjdk.org
Tue Apr 18 17:12:47 UTC 2023
On Tue, 18 Apr 2023 14:30:56 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
>> src/java.base/share/classes/sun/nio/cs/StreamEncoder.java line 439:
>>
>>> 437: if (ch != null)
>>> 438: ch.close();
>>> 439: else {
>>
>> If this encoder is for an OutputStreamWriter, and the flush of the left over characters fails, then the finally block will attempt to flush the underlying output stream again. Need to you think about that scenario a bit to decide if the underlying flush should be done for this case or not.
>
> Can we use try-with-resources instead of closing in a finally block? This way if both closing the encoder and closing the underlying stream fail, both exceptions will propagate to the user code.
> Need to think about that scenario a bit to decide if the underlying flush should be done for this case or not.
`flushLeftoverChar()` can throw an exception after having invoked `writeBytes()` once or more. This suggests that a flush of the underlying stream might be warranted.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13503#discussion_r1170344790
More information about the nio-dev
mailing list