mirror of https://github.com/apache/lucene.git
LUCENE-825: detect null returned from Directory.list() and throw IOException not NPE
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@516120 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
57cf17d188
commit
07a632c0e9
|
@ -84,6 +84,8 @@ final class IndexFileDeleter {
|
|||
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++) {
|
||||
|
||||
|
|
|
@ -236,6 +236,9 @@ final class SegmentInfo {
|
|||
// 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();
|
||||
|
|
|
@ -113,7 +113,7 @@ final class SegmentInfos extends Vector {
|
|||
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,12 +477,12 @@ final class SegmentInfos extends Vector {
|
|||
if (0 == method) {
|
||||
if (directory != null) {
|
||||
files = directory.list();
|
||||
if (files == null)
|
||||
throw new FileNotFoundException("cannot read directory " + directory + ": list() returned null");
|
||||
} else {
|
||||
files = fileDirectory.list();
|
||||
}
|
||||
|
||||
if (files == null) {
|
||||
throw new FileNotFoundException("no segments* file found in directory " + directory + ": list() returned null");
|
||||
if (files == null)
|
||||
throw new FileNotFoundException("cannot read directory " + fileDirectory + ": list() returned null");
|
||||
}
|
||||
|
||||
gen = getCurrentSegmentGeneration(files);
|
||||
|
|
|
@ -42,7 +42,11 @@ public abstract class Directory {
|
|||
* 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 abstract class Directory {
|
|||
*/
|
||||
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;
|
||||
|
|
|
@ -239,7 +239,7 @@ public class FSDirectory extends Directory {
|
|||
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())
|
||||
|
|
|
@ -980,7 +980,7 @@ public class TestIndexReader extends TestCase
|
|||
Directory dir = FSDirectory.getDirectory(dirFile);
|
||||
try {
|
||||
IndexReader reader = IndexReader.open(dir);
|
||||
fail("expected CorruptIndexException");
|
||||
fail("expected FileNotFoundException");
|
||||
} catch (FileNotFoundException e) {
|
||||
// expected
|
||||
}
|
||||
|
@ -990,7 +990,7 @@ public class TestIndexReader extends TestCase
|
|||
// Make sure we still get a CorruptIndexException (not NPE):
|
||||
try {
|
||||
IndexReader reader = IndexReader.open(dir);
|
||||
fail("expected CorruptIndexException");
|
||||
fail("expected FileNotFoundException");
|
||||
} catch (FileNotFoundException e) {
|
||||
// expected
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue