Index: src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReader.java (revision 515527) +++ src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -981,7 +981,7 @@ try { IndexReader reader = IndexReader.open(dir); fail("expected CorruptIndexException"); - } catch (FileNotFoundException e) { + } catch (IOException e) { // expected } @@ -991,7 +991,7 @@ try { IndexReader reader = IndexReader.open(dir); fail("expected CorruptIndexException"); - } catch (FileNotFoundException e) { + } catch (IOException e) { // expected } } Index: src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfos.java (revision 515527) +++ src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -113,7 +113,7 @@ public static long getCurrentSegmentGeneration(Directory directory) throws IOException { String[] files = directory.list(); if (files == null) - throw new IOException("Cannot read directory " + directory); + throw new IOException("cannot read directory " + directory + ": list() returned null"); return getCurrentSegmentGeneration(files); } @@ -477,14 +477,14 @@ if (0 == method) { if (directory != null) { files = directory.list(); + if (files == null) + throw new IOException("cannot read directory " + directory + ": list() returned null"); } else { files = fileDirectory.list(); + if (files == null) + throw new IOException("cannot read directory " + fileDirectory + ": list() returned null"); } - if (files == null) { - throw new FileNotFoundException("no segments* file found in directory " + directory + ": list() returned null"); - } - gen = getCurrentSegmentGeneration(files); if (gen == -1) { Index: src/java/org/apache/lucene/index/IndexFileDeleter.java =================================================================== --- src/java/org/apache/lucene/index/IndexFileDeleter.java (revision 515527) +++ src/java/org/apache/lucene/index/IndexFileDeleter.java (working copy) @@ -84,6 +84,8 @@ IndexFileNameFilter filter = IndexFileNameFilter.getFilter(); String[] files = directory.list(); + if (files == null) + throw new IOException("cannot read directory " + directory + ": list() returned null"); for (int i = 0; i < files.length; i++) { Index: src/java/org/apache/lucene/index/SegmentInfo.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfo.java (revision 515527) +++ src/java/org/apache/lucene/index/SegmentInfo.java (working copy) @@ -236,6 +236,9 @@ // code. So we must fallback to the original // directory list check: String[] result = dir.list(); + if (result == null) + throw new IOException("cannot read directory " + dir + ": list() returned null"); + String pattern; pattern = name + ".s"; int patternLength = pattern.length(); Index: src/java/org/apache/lucene/store/Directory.java =================================================================== --- src/java/org/apache/lucene/store/Directory.java (revision 515527) +++ src/java/org/apache/lucene/store/Directory.java (working copy) @@ -42,7 +42,11 @@ * this Directory instance). */ protected LockFactory lockFactory; - /** Returns an array of strings, one for each file in the directory. */ + /** Returns an array of strings, one for each file in the + * directory. This method may return null (for example for + * {@link FSDirectory} if the underlying directory doesn't + * exist in the filesystem or there are permissions + * problems).*/ public abstract String[] list() throws IOException; @@ -154,6 +158,10 @@ */ public static void copy(Directory src, Directory dest, boolean closeDirSrc) throws IOException { final String[] files = src.list(); + + if (files == null) + throw new IOException("cannot read directory " + src + ": list() returned null"); + byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE]; for (int i = 0; i < files.length; i++) { IndexOutput os = null; Index: src/java/org/apache/lucene/store/FSDirectory.java =================================================================== --- src/java/org/apache/lucene/store/FSDirectory.java (revision 515527) +++ src/java/org/apache/lucene/store/FSDirectory.java (working copy) @@ -239,7 +239,7 @@ if (directory.exists()) { String[] files = directory.list(IndexFileNameFilter.getFilter()); // clear old files if (files == null) - throw new IOException("Cannot read directory " + directory.getAbsolutePath()); + throw new IOException("cannot read directory " + directory.getAbsolutePath() + ": list() returned null"); for (int i = 0; i < files.length; i++) { File file = new File(directory, files[i]); if (!file.delete())