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

Reviewed-by: djelinski, vtewari
This commit is contained in:
Brian Burkhalter 2023-07-21 15:21:02 +00:00
parent 8042a50b99
commit d55d7e8d87
4 changed files with 190 additions and 17 deletions

View file

@ -414,8 +414,8 @@ public final class StreamEncoder extends Writer {
}
void implClose() throws IOException {
flushLeftoverChar(null, true);
try {
try (ch; out) {
flushLeftoverChar(null, true);
for (;;) {
CoderResult cr = encoder.flush(bb);
if (cr.isUnderflow())
@ -430,15 +430,8 @@ public final class StreamEncoder extends Writer {
if (bb.position() > 0)
writeBytes();
if (ch != null)
ch.close();
else {
try {
out.flush();
} finally {
out.close();
}
}
if (out != null)
out.flush();
} catch (IOException x) {
encoder.reset();
throw x;