lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r516120 - in /lucene/java/trunk/src: java/org/apache/lucene/index/ java/org/apache/lucene/store/ test/org/apache/lucene/index/
Date Thu, 08 Mar 2007 17:59:12 GMT
Author: mikemccand
Date: Thu Mar  8 09:59:11 2007
New Revision: 516120

URL: http://svn.apache.org/viewvc?view=rev&rev=516120
Log:
LUCENE-825: detect null returned from Directory.list() and throw IOException not NPE

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java?view=diff&rev=516120&r1=516119&r2=516120
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java Thu Mar  8 09:59:11
2007
@@ -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++) {
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java?view=diff&rev=516120&r1=516119&r2=516120
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java Thu Mar  8 09:59:11
2007
@@ -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();

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?view=diff&rev=516120&r1=516119&r2=516120
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Thu Mar  8 09:59:11
2007
@@ -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,12 +477,12 @@
         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);

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java?view=diff&rev=516120&r1=516119&r2=516120
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/Directory.java Thu Mar  8 09:59:11
2007
@@ -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;

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=516120&r1=516119&r2=516120
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Thu Mar  8 09:59:11
2007
@@ -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())

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?view=diff&rev=516120&r1=516119&r2=516120
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Thu Mar  8 09:59:11
2007
@@ -980,7 +980,7 @@
       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 @@
       // 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
       }



Mime
View raw message