RFR: 8136895: Writer not closed with disk full error, file resource leaked

Daniel Jeliński djelinski at openjdk.org
Tue Apr 18 14:33:50 UTC 2023


On Tue, 18 Apr 2023 07:28:47 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> In`StreamEncoder::implClose`, move `flushLeftoverChar()` inside the `try` block and the closing of the underlying stream inside the `finally` block.
>
> 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.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13503#discussion_r1170130400


More information about the nio-dev mailing list