Solr
  1. Solr
  2. SOLR-39

Searcher's getDocListAndSet methods do not accept flags, can cause NPE when writing output

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.0
    • Component/s: search
    • Labels:
      None

      Description

      SolrIndexSearcher's getDocListAndSet methods do not accept flags, which can, in some cases, cause a Null Pointer Exception to be thrown when writing the docListAndSet.docList as output. I came across the issue as I was implementing faceting, see http://www.nabble.com/Faceted-Browsing-Question-Discussion-tf1968854.html for the discussion.

      The simplest way to reproduce this is to modify DisMaxRequestHandler, by changing this:

      DocList results = s.getDocList(query, restrictions,
      SolrPluginUtils.getSort(req),
      req.getStart(), req.getLimit(),
      flags);
      rsp.add("search-results",results);

      to

      DocListAndSet listAndSet= s.getDocListAndSet(query, restrictions,
      SolrPluginUtils.getSort(req),
      req.getStart(), req.getLimit());
      DocList results = listAndSet.docList;
      rsp.add("search-results",results);

      The root cause appears to be that the scores[] is set to null, so then the DocIterator and its score() method is called, return scores[pos-1] will give null. When getDocListAndSet(..) is invoked, it eventually can get down to this private method:

      private DocSet getDocListAndSetNC(DocListAndSet out, Query query, DocSet filter, Sort lsort, int offset, int len, int flags) throws IOException

      In that method, scores is assigned as follows:

      scores = (flags&GET_SCORES)!=0 ? new float[nDocsReturned] : null;

      Since getDocListAndSet() does not pass flags (except for the implicit GET_DOCSET), scores is assigned as null, which eventually leads to the NullPointerException if you try to output the docList . The attached patch does not change the underlying mechanism of how scores is assigned, but works around the issue by adding overloaded getDocListAndSet() methods that take an additional flags parameter. After applying this patch, you can change the relevant bit in DisMaxRequestHandler to:

      DocListAndSet listAndSet= s.getDocListAndSet(query, restrictions,
      SolrPluginUtils.getSort(req),
      req.getStart(), req.getLimit(), flags);
      DocList results = listAndSet.docList;
      rsp.add("search-results",results);

      and you will no longer see the NullPointerException

        Issue Links

          Activity

          Hide
          Yonik Seeley added a comment -

          Thanks Greg, I just committed this.

          Show
          Yonik Seeley added a comment - Thanks Greg, I just committed this.
          Hide
          Hoss Man added a comment -

          This bug was modified as part of a bulk update using the criteria...

          • Marked ("Resolved" or "Closed") and "Fixed"
          • Had no "Fix Version" versions
          • Was listed in the CHANGES.txt for 1.1

          The Fix Version for all 38 issues found was set to 1.1, email notification
          was suppressed to prevent excessive email.

          For a list of all the issues modified, search jira comments for this
          (hopefully) unique string: 20080415hossman3

          Show
          Hoss Man added a comment - This bug was modified as part of a bulk update using the criteria... Marked ("Resolved" or "Closed") and "Fixed" Had no "Fix Version" versions Was listed in the CHANGES.txt for 1.1 The Fix Version for all 38 issues found was set to 1.1, email notification was suppressed to prevent excessive email. For a list of all the issues modified, search jira comments for this (hopefully) unique string: 20080415hossman3

            People

            • Assignee:
              Yonik Seeley
              Reporter:
              Greg Ludington
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development