Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-39

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.1.0
    • search
    • 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

      Attachments

        Issue Links

          Activity

            People

              yseeley@gmail.com Yonik Seeley
              gludington Greg Ludington
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: