Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5945: fix test bug, ensure 'dir' is always closed

Robert Muirb23b1037a669
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
index f4d9972ee3c..5c8928b54b7 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
@@ -159,21 +159,21 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads {
if (exc != null) {
throw exc;
} else {
- BaseDirectoryWrapper dir = newFSDirectory(dirPath);
- dir.setCheckIndexOnClose(false); // don't double-checkindex
- if (DirectoryReader.indexExists(dir)) {
- if (VERBOSE) {
- System.err.println("Checking index: " + dirPath);
- }
- // LUCENE-4738: if we crashed while writing first
- // commit it's possible index will be corrupt (by
- // design we don't try to be smart about this case
- // since that too risky):
- if (SegmentInfos.getLastCommitGeneration(dir) > 1) {
- TestUtil.checkIndex(dir);
+ try (BaseDirectoryWrapper dir = newFSDirectory(dirPath)) {
+ dir.setCheckIndexOnClose(false); // don't double-checkindex
+ if (DirectoryReader.indexExists(dir)) {
+ if (VERBOSE) {
+ System.err.println("Checking index: " + dirPath);
+ }
+ // LUCENE-4738: if we crashed while writing first
+ // commit it's possible index will be corrupt (by
+ // design we don't try to be smart about this case
+ // since that too risky):
+ if (SegmentInfos.getLastCommitGeneration(dir) > 1) {
+ TestUtil.checkIndex(dir);
+ }
+ found.set(true);
}
- dir.close();
- found.set(true);
}
return FileVisitResult.CONTINUE;
}