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:56 UTC

lucene-solr:branch_7x: LUCENE-8212: Ensure all closeables are closed even if an VMError is thrown

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 32c8540d5 -> af33bc8c3


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/af33bc8c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/af33bc8c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/af33bc8c

Branch: refs/heads/branch_7x
Commit: af33bc8c3bbf15f8b56e9af0033b897c034176e6
Parents: 32c8540
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:36:44 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/af33bc8c/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;
     }
   }