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

SolrJ FacetField should never return null from getValues()

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4.1
    • Fix Version/s: 4.0-ALPHA
    • Component/s: clients - java
    • Labels:
      None

      Description

      In some circumstances, FacetField.getValues() will return null. I'd like for my iteration code to simply be:

      for (c : ff.getValues() { 
        // ...
      }
      

      However this will throw an NPE if I don't wrap this in either a null check or this check: ff.getValueCount() > 0

      I propose that getValues() return a Collections.EMPTY_LIST if the internal value is null.

        Activity

        Hide
        szott Sascha Szott added a comment -

        At least a notice should be added to the Javadoc method description since it seems to be uncommon to respond with null in case of an empty facet field.

        Show
        szott Sascha Szott added a comment - At least a notice should be added to the Javadoc method description since it seems to be uncommon to respond with null in case of an empty facet field.
        Hide
        cmale Chris Male added a comment -

        Also a frustration of mine. I'll put something together.

        Show
        cmale Chris Male added a comment - Also a frustration of mine. I'll put something together.
        Hide
        cmale Chris Male added a comment -

        Patch which fixes the problem and adds a trivial test to prevent regression.

        Ready to go.

        Show
        cmale Chris Male added a comment - Patch which fixes the problem and adds a trivial test to prevent regression. Ready to go.
        Hide
        ryantxu Ryan McKinley added a comment -

        +1

        Show
        ryantxu Ryan McKinley added a comment - +1
        Hide
        cmale Chris Male added a comment -

        Committed revision 1144561.

        Show
        cmale Chris Male added a comment - Committed revision 1144561.

          People

          • Assignee:
            cmale Chris Male
            Reporter:
            dsmiley David Smiley
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development