Merge pull request #490 from iamsanjaymalakar/master

Fix ConcatReader.close() to close all readers on failure
This commit is contained in:
SuperMonster003
2026-03-14 22:47:17 +08:00
committed by GitHub
2 changed files with 16 additions and 2 deletions

View File

@@ -383,10 +383,17 @@ public class ConcatReader extends Reader {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
if (closed) return; if (closed) return;
IOException first = null;
for (Reader reader : readerQueue) { for (Reader reader : readerQueue) {
reader.close(); try {
reader.close();
} catch (IOException e) {
if (first == null) first = e;
else first.addSuppressed(e);
}
} }
closed = true; closed = true;
if (first != null) throw first;
} }
/** /**

View File

@@ -381,10 +381,17 @@ public class ConcatReader extends Reader {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
if (closed) return; if (closed) return;
IOException first = null;
for (Reader reader : readerQueue) { for (Reader reader : readerQueue) {
reader.close(); try {
reader.close();
} catch (IOException e) {
if (first == null) first = e;
else first.addSuppressed(e);
}
} }
closed = true; closed = true;
if (first != null) throw first;
} }
/** /**