diff --git a/CHANGES.txt b/CHANGES.txt index 82c2368c229..cb67b1838f0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -43,6 +43,11 @@ Bug fixes IndexWriter's mergeSegments, and also during IndexWriter.addIndexes. (Mike McCandless) + 6. LUCENE-825: If directory is removed after + FSDirectory.getDirectory() but before IndexReader.open you now get + a FileNotFoundException like Lucene pre-2.1 (before this fix you + got an NPE). (Mike McCandless) + New features 1. LUCENE-759: Added two n-gram-producing TokenFilters. diff --git a/src/java/org/apache/lucene/index/SegmentInfos.java b/src/java/org/apache/lucene/index/SegmentInfos.java index ad34782aa69..a4ffe899516 100644 --- a/src/java/org/apache/lucene/index/SegmentInfos.java +++ b/src/java/org/apache/lucene/index/SegmentInfos.java @@ -481,6 +481,10 @@ final class SegmentInfos extends Vector { files = fileDirectory.list(); } + if (files == null) { + throw new FileNotFoundException("no segments* file found in directory " + directory + ": list() returned null"); + } + gen = getCurrentSegmentGeneration(files); if (gen == -1) { diff --git a/src/test/org/apache/lucene/index/TestIndexReader.java b/src/test/org/apache/lucene/index/TestIndexReader.java index 01ab81a7dd0..e2796810903 100644 --- a/src/test/org/apache/lucene/index/TestIndexReader.java +++ b/src/test/org/apache/lucene/index/TestIndexReader.java @@ -974,6 +974,28 @@ public class TestIndexReader extends TestCase return s; } + public void testOpenReaderAfterDelete() throws IOException { + File dirFile = new File(System.getProperty("tempDir"), + "deletetest"); + Directory dir = FSDirectory.getDirectory(dirFile); + try { + IndexReader reader = IndexReader.open(dir); + fail("expected CorruptIndexException"); + } catch (FileNotFoundException e) { + // expected + } + + dirFile.delete(); + + // Make sure we still get a CorruptIndexException (not NPE): + try { + IndexReader reader = IndexReader.open(dir); + fail("expected CorruptIndexException"); + } catch (FileNotFoundException e) { + // expected + } + } + private void deleteReaderReaderConflict(boolean optimize) throws IOException { Directory dir = getDirectory();