From a97703f1dfcb4d684fa8bf76e17381ad2da7404a Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 3 Oct 2012 15:22:53 +0000 Subject: [PATCH] handle Throwable not just IOE when closing git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/slowclosing@1393535 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/StandardDirectoryReader.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java index 3f144a8cbba..a9761312d03 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java @@ -334,13 +334,13 @@ final class StandardDirectoryReader extends DirectoryReader { @Override protected void doClose() throws IOException { - IOException ioe = null; + Throwable firstExc = null; for (final AtomicReader r : getSequentialSubReaders()) { // try to close each reader, even if an exception is thrown try { r.decRef(); - } catch (IOException e) { - if (ioe == null) ioe = e; + } catch (Throwable t) { + if (t == null) firstExc = t; } } @@ -351,7 +351,12 @@ final class StandardDirectoryReader extends DirectoryReader { } // throw the first exception - if (ioe != null) throw ioe; + if (firstExc != null) { + if (firstExc instanceof IOException) throw (IOException) firstExc; + if (firstExc instanceof RuntimeException) throw (RuntimeException) firstExc; + if (firstExc instanceof Error) throw (Error) firstExc; + throw new RuntimeException(firstExc); + } } @Override