You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Tim Brennan (JIRA)" <ji...@apache.org> on 2007/03/07 02:12:24 UTC

[jira] Created: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
-------------------------------------------------------------------------------------------------

                 Key: LUCENE-825
                 URL: https://issues.apache.org/jira/browse/LUCENE-825
             Project: Lucene - Java
          Issue Type: Bug
    Affects Versions: 2.1
            Reporter: Tim Brennan


Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)

If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.

Repro:
    1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
    2) rm -rf the parent dir (rm -rf /foo/index)
    3) Try to open an IndexReader

Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
 
Expect: IOException


....  

This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():

        if (0 == method) {
          if (directory != null) {
            files = directory.list();
          } else {
            files = fileDirectory.list();
          }

          gen = getCurrentSegmentGeneration(files);

          if (gen == -1) {
            String s = "";
            for(int i=0;i<files.length;i++) { 
              s += " " + files[i];
            }
            throw new FileNotFoundException("no segments* file found: files:" + s);
          }
        }


The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:

(in org/apache/lucene/store/FSDirectory.java)
314c314,317
<         return directory.list(IndexFileNameFilter.getFilter());
---
>     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
>     if (toRet == null)
>         return new String[]{};
>     return toRet;


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Commented: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478704 ] 

Michael McCandless commented on LUCENE-825:
-------------------------------------------

Whoa, thanks for catching this!

I would rather leave FSDirectory.list() returning null when the
directory does not exist because that would be an API change that
makes me a little nervous.

I'll instead fix it in SegmentInfos and add a unit test showing the
bug.

Index: src/java/org/apache/lucene/index/SegmentInfos.java
===================================================================
--- src/java/org/apache/lucene/index/SegmentInfos.java	(revision 515317)
+++ src/java/org/apache/lucene/index/SegmentInfos.java	(working copy)
@@ -481,6 +481,10 @@
             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) {


> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Resolved: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless resolved LUCENE-825.
---------------------------------------

       Resolution: Fixed
    Lucene Fields: [New, Patch Available]  (was: [Patch Available, New])

> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>             Fix For: 2.2
>
>         Attachments: LUCENE-825.patch
>
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Commented: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Tim Brennan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478733 ] 

Tim Brennan commented on LUCENE-825:
------------------------------------

The reason I suggested changing FSDirectory is that a quick look through the callers of Directory.list() show that pretty much none of the callsites expect a null return from this function. 

 Check out:

1) SegmentInfos.java - boolean hasSeparateNorms():
        String[] result = dir.list();
        String pattern;
        pattern = name + ".s";
        int patternLength = pattern.length();
        for(int i = 0; i < result.length; i++){
          if(result[i].startsWith(pattern) && Character.isDigit(result[i].charAt(patternLength)))
(accesses result.length w/o null check on result)


2) IndexFileDeleter.java - void findDeletableFiles():
    String[] files = directory.list();

    for (int i = 0; i < files.length; i++) {
(access to files.length w/o null check)

3) Directory.java - static void copy(...)
....same thing...


Should probably fix all those callsites as well, if we really expect Directory.list() to return null...




> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>             Fix For: 2.2
>
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Reopened: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless reopened LUCENE-825:
---------------------------------------

    Lucene Fields: [New, Patch Available]  (was: [Patch Available, New])

> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>             Fix For: 2.2
>
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Resolved: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless resolved LUCENE-825.
---------------------------------------

       Resolution: Fixed
    Fix Version/s: 2.2
    Lucene Fields: [New, Patch Available]  (was: [Patch Available, New])

Thanks Tim.  Keep the patches coming!

> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>             Fix For: 2.2
>
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Assigned: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless reassigned LUCENE-825:
-----------------------------------------

    Assignee: Michael McCandless

> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Updated: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless updated LUCENE-825:
--------------------------------------

    Attachment: LUCENE-825.patch

Attached patch to check all places internal to Lucene where we call Directory.list().  I also updated the javadoc of that method to state that it may return null.

> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>             Fix For: 2.2
>
>         Attachments: LUCENE-825.patch
>
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


[jira] Commented: (LUCENE-825) NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-825?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478738 ] 

Michael McCandless commented on LUCENE-825:
-------------------------------------------

Excellent point.  I will do that.

> NullPointerException from SegmentInfos.FindSegmentsFile.run() if FSDirectory.list() returns NULL 
> -------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-825
>                 URL: https://issues.apache.org/jira/browse/LUCENE-825
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.1
>            Reporter: Tim Brennan
>         Assigned To: Michael McCandless
>             Fix For: 2.2
>
>
> Found this bug while running unit tests to verify an upgrade of our system from 1.4.3 to 2.1.0.  This bug did *not* occur during 1.4.3, it is new to 2.x (I'm pretty sure it's 2.1-only)
> If the index directory gets deleted out from under Lucene after the FSDirectory has been created, then attempts to open an IndexWriter or IndexReader will result in an NPE.  Lucene should be throwing an IOException in this case.
> Repro:
>     1) Create an FSDirectory pointing somewhere in the filesystem (e.g. /foo/index/1)
>     2) rm -rf the parent dir (rm -rf /foo/index)
>     3) Try to open an IndexReader
> Result: NullPointerException on line "for(int i=0;i<files.length;i++) { " -- 'files' is NULL.
>  
> Expect: IOException
> ....  
> This is happening because of a missing NULL check in SegmentInfos$FindSegmentsFile.run():
>         if (0 == method) {
>           if (directory != null) {
>             files = directory.list();
>           } else {
>             files = fileDirectory.list();
>           }
>           gen = getCurrentSegmentGeneration(files);
>           if (gen == -1) {
>             String s = "";
>             for(int i=0;i<files.length;i++) { 
>               s += " " + files[i];
>             }
>             throw new FileNotFoundException("no segments* file found: files:" + s);
>           }
>         }
> The FSDirectory constructor will make sure the index dir exists, but if it is for some reason deleted out from underneath Lucene after the FSDirectory is instantiated, then java.io.File.list() will return NULL.  Probably better to fix FSDirectory.list() to just check for null and return a 0-length array:
> (in org/apache/lucene/store/FSDirectory.java)
> 314c314,317
> <         return directory.list(IndexFileNameFilter.getFilter());
> ---
> >     String[] toRet = directory.list(IndexFileNameFilter.getFilter());
> >     if (toRet == null)
> >         return new String[]{};
> >     return toRet;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org