lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Brennan (JIRA)" <>
Subject [jira] Created: (LUCENE-825) NullPointerException from if FSDirectory.list() returns NULL
Date Wed, 07 Mar 2007 01:12:24 GMT
NullPointerException from if FSDirectory.list() returns

                 Key: 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.

    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
Expect: IOException


This is happening because of a missing NULL check in SegmentInfos$

        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
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/
<         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:
For additional commands, e-mail:

View raw message