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

SolrJ fails with a NullPointerException when the order of result components changes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.4
    • 3.1, 4.0-ALPHA
    • clients - java
    • None

    Description

      When using a custom search component in Solr I noticed that the order of the "params", "response" and "facet_counts" fields in the response changed. Normally the "response" field is included before the "facet_counts" field, but in my result it first returned "facet_counts" and then "response". This is of course a valid and semantically identical result object, but it causes SolrJ to fail with a NullPointerException.

      The reason for this NPE is that SolrJ in org.apache.solr.client.solrj.response.QueryResponse.setResponse(NamedList<Object> res) uses a loop through the response components and right after encountering "facet_counts" calls extractFacetInfo( _facetInfo ). That method uses _results which is null if the "response" component has not been encountered yet. (It is handled and set a few lines above the call to extractFacetInfo).

      The solution is to move the call to extractFacetInfo() on line 99 out of the for-loop. Please see the attached simple patch for the solution.

      I have also checked the three other initialization calls that are made directly after encountering a result (extractDebugInfo, extractHighlightingInfo and extractSpellCheckInfo), the problem does not apply to those because the methods don't access global fields that need to be initialized.

      Note: It would be great if this could be applied to a maintenance release as it saves people from running a custom build to be able to use complex search components with SolrJ.

      Attachments

        1. SOLR-2085-QueryResponse.patch
          0.7 kB
          Tomas Salfischberger

        Activity

          People

            hossman Chris M. Hostetter
            t0mas Tomas Salfischberger
            Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: