You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/09/14 19:41:51 UTC

svn commit: r1624882 - /lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java

Author: rmuir
Date: Sun Sep 14 17:41:51 2014
New Revision: 1624882

URL: http://svn.apache.org/r1624882
Log:
LUCENE-5945: fix test bug, ensure 'dir' is always closed

Modified:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java?rev=1624882&r1=1624881&r2=1624882&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java Sun Sep 14 17:41:51 2014
@@ -159,21 +159,21 @@ public class TestIndexWriterOnJRECrash e
         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;
         }