You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2018/03/21 08:36:07 UTC
lucene-solr:master: LUCENE-8212: Ensure all closeables are closed
even if an VMError is thrown
Repository: lucene-solr
Updated Branches:
refs/heads/master d2ef38d78 -> f664896d1
LUCENE-8212: Ensure all closeables are closed even if an VMError is thrown
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/f664896d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/f664896d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/f664896d
Branch: refs/heads/master
Commit: f664896d1fff951bb50aae414b043f97bb9159b8
Parents: d2ef38d
Author: Simon Willnauer <si...@apache.org>
Authored: Wed Mar 21 09:35:15 2018 +0100
Committer: Simon Willnauer <si...@apache.org>
Committed: Wed Mar 21 09:35:56 2018 +0100
----------------------------------------------------------------------
.../src/java/org/apache/lucene/util/IOUtils.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f664896d/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java b/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
index 766d6fb..350ae43 100644
--- a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
+++ b/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
@@ -113,19 +113,31 @@ public final class IOUtils {
}
/**
- * Closes all given <tt>Closeable</tt>s, suppressing all thrown exceptions.
+ * Closes all given <tt>Closeable</tt>s, suppressing all thrown non {@link VirtualMachineError} exceptions.
+ * Even if a {@link VirtualMachineError} is thrown all given closeable are closed.
* @see #closeWhileHandlingException(Closeable...)
*/
public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) {
+ VirtualMachineError firstError = null;
+ Throwable firstThrowable = null;
for (Closeable object : objects) {
try {
if (object != null) {
object.close();
}
} catch (VirtualMachineError e) {
- throw e;
+ firstError = useOrSuppress(firstError, e);
} catch (Throwable t) {
+ firstThrowable = useOrSuppress(firstThrowable, t);
+ }
+ }
+ if (firstError != null) {
+ // we ensure that we bubble up any errors. We can't recover from these but need to make sure they are
+ // bubbled up. if a non-VMError is thrown we also add the suppressed exceptions to it.
+ if (firstThrowable != null) {
+ firstError.addSuppressed(firstThrowable);
}
+ throw firstError;
}
}