Solr
  1. Solr
  2. SOLR-2085

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 3.1, 4.0-ALPHA
    • Component/s: clients - java
    • Labels:
      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.

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

        Activity

        Tomas Salfischberger created issue -
        Tomas Salfischberger made changes -
        Field Original Value New Value
        Attachment SOLR-2085-QueryResponse.patch [ 12452924 ]
        Hoss Man made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Hoss Man [ hossman ]
        Fix Version/s 3.1 [ 12314371 ]
        Fix Version/s 4.0 [ 12314992 ]
        Resolution Fixed [ 1 ]
        Grant Ingersoll made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Hoss Man
            Reporter:
            Tomas Salfischberger
          • Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development