Solr
  1. Solr
  2. SOLR-1021

NullPointerException(s) in SolrJ when using stats and result set is empty

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.4
    • Component/s: clients - java
    • Labels:
      None
    • Environment:

      Tomcat 6, Windows

      Description

      A NullPointerException is thrown at line 51 of class FieldStatsInfo since the returned stats information for the fname (ctor variable) is null and not checked for being so.

      Seems like this occurs when the search returns with no results but there were some setGetFieldStatistics defined for some fields.

      1. SOLR-1021.patch
        1 kB
        Rohit Gandhe
      2. QueryResponse.java
        11 kB
        Arie Fishler

        Activity

        Hide
        Arie Fishler added a comment -

        Added an if statement to avoid the ctor of FieldStatsInfo

        Show
        Arie Fishler added a comment - Added an if statement to avoid the ctor of FieldStatsInfo
        Hide
        Hoss Man added a comment -

        Arie: I'm not sure that i really understand the problem you're describing, and it looks like perhaps you didn't attach the file you ment to attach.

        Can you post a stack trace showing the NPE you're describing?

        Also: If you haven't already seen it http://wiki.apache.org/solr/HowToContribute has some info on generating patches with bug fixes.

        Show
        Hoss Man added a comment - Arie: I'm not sure that i really understand the problem you're describing, and it looks like perhaps you didn't attach the file you ment to attach. Can you post a stack trace showing the NPE you're describing? Also: If you haven't already seen it http://wiki.apache.org/solr/HowToContribute has some info on generating patches with bug fixes.
        Hide
        Arie Fishler added a comment -

        I'll start from scratch since it might be possible I generated some mess here

        In FieldStatsInfo I got a NullPointerException in line 51 which indicated that the nl variable passed to the constructor is probaby null
        FieldStatsInfo( NamedList<Object> nl, String fname )

        Constructor is only called from QueryResponse.java and I added the if statement there to avoid the exception (and not call the constructor when this occurs. I did not get too deep into that but seems like there might be a situation when the stat info is null for some fields.
        I am not sure if this is the best solution or it might indicate another problem. This solution works for me.

        Show
        Arie Fishler added a comment - I'll start from scratch since it might be possible I generated some mess here In FieldStatsInfo I got a NullPointerException in line 51 which indicated that the nl variable passed to the constructor is probaby null FieldStatsInfo( NamedList<Object> nl, String fname ) Constructor is only called from QueryResponse.java and I added the if statement there to avoid the exception (and not call the constructor when this occurs. I did not get too deep into that but seems like there might be a situation when the stat info is null for some fields. I am not sure if this is the best solution or it might indicate another problem. This solution works for me.
        Hide
        Arie Fishler added a comment -

        This is the correct file. My change is at line 134.

        I can try later on and generate a more appropriate contribution on this according to the guidelines. Could not get to it right now

        Show
        Arie Fishler added a comment - This is the correct file. My change is at line 134. I can try later on and generate a more appropriate contribution on this according to the guidelines. Could not get to it right now
        Hide
        Rohit Gandhe added a comment -

        This patch contains Arie's fix and an additional (related) fix I had to make when extracting facet info in QueryResponse. As he mentioned earlier, the NPE is thrown when trying to extract stats and facets from a resultset which contain 0 docs.

        Show
        Rohit Gandhe added a comment - This patch contains Arie's fix and an additional (related) fix I had to make when extracting facet info in QueryResponse. As he mentioned earlier, the NPE is thrown when trying to extract stats and facets from a resultset which contain 0 docs.
        Hide
        Hoss Man added a comment -

        The bug with stats makes sense – the question is what behavior would be better for clients:

        1) leave the _fieldStatsInfo Map empty
        2) populate _fieldStatsInfo with all of the fields that were returned as keys, but null for hte values
        3) populate _fieldStatsInfo with "empty" FieldStatsInfo objects (so all the accessors – ie: FieldStatsInfo.getCount() – return null)

        #2 & #3 being alternate methods for conveying to clients which fields they would have gotten stats for if the result set hadn't been empty.

        any of these approaches is relatively trivial to implement, it's just a question of which will be the best for clients.

        I don't really understand the change to extractFacetInfo in the patch. even with an empty result set, the facet_query NamedList will never contain a null value – they will all be zeros. ... can someone post a stack trace (and explanation of what the request looked like) where the current code caused a problem?

        Show
        Hoss Man added a comment - The bug with stats makes sense – the question is what behavior would be better for clients: 1) leave the _fieldStatsInfo Map empty 2) populate _fieldStatsInfo with all of the fields that were returned as keys, but null for hte values 3) populate _fieldStatsInfo with "empty" FieldStatsInfo objects (so all the accessors – ie: FieldStatsInfo.getCount() – return null) #2 & #3 being alternate methods for conveying to clients which fields they would have gotten stats for if the result set hadn't been empty. any of these approaches is relatively trivial to implement, it's just a question of which will be the best for clients. I don't really understand the change to extractFacetInfo in the patch. even with an empty result set, the facet_query NamedList will never contain a null value – they will all be zeros. ... can someone post a stack trace (and explanation of what the request looked like) where the current code caused a problem?
        Hide
        Shalin Shekhar Mangar added a comment -

        This might have been fixed by Ryan in revision r763791.

        Can somebody use a recent nightly (or trunk) and confirm?

        Show
        Shalin Shekhar Mangar added a comment - This might have been fixed by Ryan in revision r763791. Can somebody use a recent nightly (or trunk) and confirm?
        Hide
        Noble Paul added a comment -

        there is a fix that is already checked in Rohit ,is the fix good enough ?

        Show
        Noble Paul added a comment - there is a fix that is already checked in Rohit ,is the fix good enough ?
        Hide
        Shalin Shekhar Mangar added a comment -

        Marking this as fixed. We can re-open if the problem still exists.

        Show
        Shalin Shekhar Mangar added a comment - Marking this as fixed. We can re-open if the problem still exists.
        Hide
        Grant Ingersoll added a comment -

        Bulk close for Solr 1.4

        Show
        Grant Ingersoll added a comment - Bulk close for Solr 1.4

          People

          • Assignee:
            Noble Paul
            Reporter:
            Arie Fishler
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development