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

        Hide
        Grant Ingersoll added a comment -

        Bulk close for 3.1.0 release

        Show
        Grant Ingersoll added a comment - Bulk close for 3.1.0 release
        Hide
        Hoss Man added a comment -

        Thanks for the patch Tomas.

        By the looks of it, someone already fixed the NPE, but the code would still behave differently depending on the output order – i've added your patch along with a note about why delayed execution is important.

        Committed revision 1064386. - trunk
        Committed revision 1064390. - 3x

        Show
        Hoss Man added a comment - Thanks for the patch Tomas. By the looks of it, someone already fixed the NPE, but the code would still behave differently depending on the output order – i've added your patch along with a note about why delayed execution is important. Committed revision 1064386. - trunk Committed revision 1064390. - 3x

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development