Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

handle Throwable not just IOE when closing

Michael McCandlessa97703f1dfcb
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