lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r783314 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexReader.java test/org/apache/lucene/index/TestIndexReader.java
Date Wed, 10 Jun 2009 12:21:28 GMT
Author: uschindler
Date: Wed Jun 10 12:21:27 2009
New Revision: 783314

URL: http://svn.apache.org/viewvc?rev=783314&view=rev
Log:
LUCENE-1453: Fix IndexReader.open() to close directory, when open() of the underlying DirectoryReader
failed.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?rev=783314&r1=783313&r2=783314&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Wed Jun 10 12:21:27
2009
@@ -208,7 +208,7 @@
    * Use {@link #open(Directory, boolean)} instead
    * @param path the path to the index directory */
   public static IndexReader open(String path) throws CorruptIndexException, IOException {
-    return new DirectoryOwningReader(open(FSDirectory.getDirectory(path), null, null, false));
+    return open(path, false);
   }
 
   /** Returns an IndexReader reading the index in an
@@ -225,7 +225,15 @@
    * Use {@link #open(Directory, boolean)} instead
    */
   public static IndexReader open(String path, boolean readOnly) throws CorruptIndexException,
IOException {
-    return new DirectoryOwningReader(open(FSDirectory.getDirectory(path), null, null, readOnly));
+    final Directory dir = FSDirectory.getDirectory(path);
+    IndexReader r = null;
+    try {
+      r = open(dir, null, null, readOnly);
+    } finally {
+      if (r == null)
+        dir.close();
+    }
+    return new DirectoryOwningReader(r);
   }
 
   /** Returns a read/write IndexReader reading the index in an FSDirectory in the named
@@ -237,7 +245,7 @@
    * Use {@link #open(Directory, boolean)} instead
    */
   public static IndexReader open(File path) throws CorruptIndexException, IOException {
-    return new DirectoryOwningReader(open(FSDirectory.getDirectory(path), null, null, false));
+    return open(path, false);
   }
 
   /** Returns an IndexReader reading the index in an
@@ -254,7 +262,15 @@
    * Use {@link #open(Directory, boolean)} instead
    */
   public static IndexReader open(File path, boolean readOnly) throws CorruptIndexException,
IOException {
-    return new DirectoryOwningReader(open(FSDirectory.getDirectory(path), null, null, readOnly));
+    final Directory dir = FSDirectory.getDirectory(path);
+    IndexReader r = null;
+    try {
+      r = open(dir, null, null, readOnly);
+    } finally {
+      if (r == null)
+        dir.close();
+    }
+    return new DirectoryOwningReader(r);
   }
 
   /** Returns a read/write IndexReader reading the index in

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=783314&r1=783313&r2=783314&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Wed Jun 10 12:21:27
2009
@@ -1202,6 +1202,8 @@
       } catch (FileNotFoundException e) {
         // expected
       }
+      
+      dir.close();
     }
 
     private void deleteReaderReaderConflict(boolean optimize) throws IOException
@@ -1543,7 +1545,7 @@
       File indexDir = new File(tempDir, "lucenetestdiralreadyclosed");
 
       try {
-        FSDirectory dir = FSDirectory.open(indexDir);
+        FSDirectory dir = FSDirectory.getDirectory(indexDir);
         IndexWriter w = new IndexWriter(indexDir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
         w.setUseCompoundFile(false);
         Document doc = new Document();
@@ -1631,6 +1633,7 @@
     } catch (NoSuchDirectoryException nsde) {
       // expected
     }
+    dir.close();
   }
 
   // LUCENE-1509



Mime
View raw message