Skip to content

Commit 87e4485

Browse files
committed
Fix assignment to final var
1 parent 85fe2fe commit 87e4485

File tree

1 file changed

+8
-7
lines changed
  • libs/elasticsearch-core/src/main/java/org/elasticsearch/core/internal/io

1 file changed

+8
-7
lines changed

libs/elasticsearch-core/src/main/java/org/elasticsearch/core/internal/io/IOUtils.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,27 @@ public static void close(final Iterable<? extends Closeable> objects) throws IOE
8787
* @see #close(Closeable...)
8888
*/
8989
public static void close(final Exception ex, final Iterable<? extends Closeable> objects) throws IOException {
90+
Exception error = ex;
9091
for (final Closeable object : objects) {
9192
try {
9293
if (object != null) {
9394
object.close();
9495
}
9596
} catch (final IOException | RuntimeException e) {
96-
if (ex == null) {
97-
ex = e;
97+
if (error == null) {
98+
error = e;
9899
} else {
99-
ex.addSuppressed(e);
100+
error.addSuppressed(e);
100101
}
101102
}
102103
}
103104

104-
if (ex != null) {
105-
if (ex instanceof IOException) {
106-
throw (IOException) ex;
105+
if (error != null) {
106+
if (error instanceof IOException) {
107+
throw (IOException) error;
107108
} else {
108109
// since we only assigned an IOException or a RuntimeException to ex above, in this case ex must be a RuntimeException
109-
throw (RuntimeException) ex;
110+
throw (RuntimeException) error;
110111
}
111112
}
112113
}

0 commit comments

Comments
 (0)