LUCENE-825: make sure FileNotFoundException is returned if directory.list() returns null

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@515495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2007-03-07 08:45:58 +00:00
parent 810700836f
commit 622d58b3f8
3 changed files with 31 additions and 0 deletions

View File

@ -43,6 +43,11 @@ Bug fixes
IndexWriter's mergeSegments, and also during IndexWriter's mergeSegments, and also during
IndexWriter.addIndexes. (Mike McCandless) 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 New features
1. LUCENE-759: Added two n-gram-producing TokenFilters. 1. LUCENE-759: Added two n-gram-producing TokenFilters.

View File

@ -481,6 +481,10 @@ final class SegmentInfos extends Vector {
files = fileDirectory.list(); files = fileDirectory.list();
} }
if (files == null) {
throw new FileNotFoundException("no segments* file found in directory " + directory + ": list() returned null");
}
gen = getCurrentSegmentGeneration(files); gen = getCurrentSegmentGeneration(files);
if (gen == -1) { if (gen == -1) {

View File

@ -974,6 +974,28 @@ public class TestIndexReader extends TestCase
return s; 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 private void deleteReaderReaderConflict(boolean optimize) throws IOException
{ {
Directory dir = getDirectory(); Directory dir = getDirectory();