Index: src/java/org/apache/lucene/index/IndexReader.java =================================================================== --- src/java/org/apache/lucene/index/IndexReader.java (revision 783280) +++ src/java/org/apache/lucene/index/IndexReader.java (working copy) @@ -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 Index: src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReader.java (revision 783246) +++ src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -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