Lucene - Core
  1. Lucene - Core
  2. LUCENE-2478

CachingWrapperFilter throws NPE when Filter.getDocIdSet() returns null

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.9.1, 2.9.2, 3.0, 3.0.1
    • Fix Version/s: 2.9.3, 3.0.2, 3.1, 4.0-ALPHA
    • Component/s: None
    • Labels:
      None
    • Lucene Fields:
      New, Patch Available

      Description

      Followup for http://www.lucidimagination.com/search/document/1014ea92f15677bd/filter_getdocidset_returning_null_and_what_this_means_for_cachingwrapperfilter:

      Daniel Noll is seeing an exception like this:

      java.lang.NullPointerException
          at org.apache.lucene.search.CachingWrapperFilter.docIdSetToCache(CachingWrapperFilter.java:84)
          at org.apache.lucene.search.CachingWrapperFilter.getDocIdSet(CachingWrapperFilter.java:112)
          at com.nuix.storage.search.LazyConstantScoreQuery$LazyFilterWrapper.getDocIdSet(SourceFile:91)
          at org.apache.lucene.search.ConstantScoreQuery$ConstantScorer.<init>(ConstantScoreQuery.java:116)
          at org.apache.lucene.search.ConstantScoreQuery$ConstantWeight.scorer(ConstantScoreQuery.java:81)
          at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:297)
          at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:297)
          at org.apache.lucene.search.QueryWrapperFilter$2.iterator(QueryWrapperFilter.java:75)
      

      The class of our own is just an intermediary which delays creating the Filter object...

      @Override
      public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
                  if (delegate == null) {
                      delegate = factory.createFilter();
                  }
                  return delegate.getDocIdSet(reader);
      }
      

      Tracing through the code in CachingWrapperFilter, I can see that this NPE would occur if getDocIdSet() were to return null.

      The Javadoc on Filter says that null will be returned if no documents will be accepted by the filter, but it doesn't seem that Lucene itself is handling null return values correctly, so which is correct? The code or the Javadoc? Supposing that null really is OK, does this cause any problems with how CachingWrapperFilter is implementing the caching? I notice it's calling get() and then comparing against null so it wouldn't appear that it can distinguish "the entry isn't in the cache" from "the entry is in the cache but it's null".

      1. LUCENE-2478.patch
        0.8 kB
        Uwe Schindler
      2. LUCENE-2478.patch
        3 kB
        Uwe Schindler

        Activity

        Hide
        Uwe Schindler added a comment -

        Committed revisions: 948429 (trunk), 948430 (3.x), 948432 (3.0), 948450 (2.9)

        Show
        Uwe Schindler added a comment - Committed revisions: 948429 (trunk), 948430 (3.x), 948432 (3.0), 948450 (2.9)
        Hide
        Uwe Schindler added a comment -

        Patch with additional tests from trunk.

        Show
        Uwe Schindler added a comment - Patch with additional tests from trunk.
        Hide
        Uwe Schindler added a comment - - edited

        This fixes this bug, will commit soon.

        The behaviour is now identical and null is handled equally to DocIdSet.EMPTY_DOCIDSET. DocIdSet.EMPTY_DOCIDSET is used in both cases to denote the empty set even when the filter returned null. By this also the null value is correctly cached without additional containsKey() checks.

        Show
        Uwe Schindler added a comment - - edited This fixes this bug, will commit soon. The behaviour is now identical and null is handled equally to DocIdSet.EMPTY_DOCIDSET. DocIdSet.EMPTY_DOCIDSET is used in both cases to denote the empty set even when the filter returned null. By this also the null value is correctly cached without additional containsKey() checks.

          People

          • Assignee:
            Uwe Schindler
            Reporter:
            Uwe Schindler
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development