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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1624882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-09-14 17:41:51 +00:00
parent 771e1e399e
commit b23b1037a6
1 changed files with 14 additions and 14 deletions

View File

@ -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);
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);
}
// 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);
}
dir.close();
found.set(true);
}
return FileVisitResult.CONTINUE;
}