Solr
  1. Solr
  2. SOLR-7508

SolrParams.toMultiMap() does not handle arrays

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 5.0, 5.1
    • Fix Version/s: None
    • Component/s: SolrJ
    • Labels:

      Description

      Following JUnit test to show what I mean:

      ModifiableSolrParams params = new ModifiableSolrParams();
      String[] paramValues = new String[] { "title:junit", "author:john" };
      String paramName = "fq";
      params.add(paramName, paramValues);
      NamedList<Object> namedList = params.toNamedList();
      assertEquals("parameter values are not equal", paramValues, namedList.get(paramName));
      Map<String, String[]> multiMap = SolrParams.toMultiMap(namedList);
      assertEquals("Expected " + paramValues.length + " values", paramValues.length, multiMap.get(paramName).length);
      

      The first assertEquals() will run fine, while the last one triggers the error. Suddenly the length of the array is "1" and it's value of fq is like [Ljava.lang.String;@6f09c9c0. Looking into the code I see that the toMultiMap() method does not even look for arrays.

      1. SOLRJ-7508.patch
        0.8 kB
        Thomas Scheffler

        Activity

        Hide
        Thomas Scheffler added a comment -

        proposed fix:

        SolrParams.java
          public static Map<String,String[]> toMultiMap(NamedList params) {
            HashMap<String,String[]> map = new HashMap<>();
            for (int i=0; i<params.size(); i++) {
              String name = params.getName(i);
              Object val = params.getVal(i);
              if (val instanceof String[]){
                MultiMapSolrParams.addParam(name,(String[])val,map);
              } else {
                MultiMapSolrParams.addParam(name,val.toString(),map);
              }
            }
            return map;
          }
        
        Show
        Thomas Scheffler added a comment - proposed fix: SolrParams.java public static Map< String , String []> toMultiMap(NamedList params) { HashMap< String , String []> map = new HashMap<>(); for ( int i=0; i<params.size(); i++) { String name = params.getName(i); Object val = params.getVal(i); if (val instanceof String []){ MultiMapSolrParams.addParam(name,( String [])val,map); } else { MultiMapSolrParams.addParam(name,val.toString(),map); } } return map; }
        Hide
        Noble Paul added a comment -

        A patch would be helpful

        Show
        Noble Paul added a comment - A patch would be helpful
        Hide
        Thomas Scheffler added a comment -

        Provided patch to fix the issue.

        Show
        Thomas Scheffler added a comment - Provided patch to fix the issue.
        Hide
        ASF subversion and git services added a comment -

        Commit 1679494 from Noble Paul in branch 'dev/trunk'
        [ https://svn.apache.org/r1679494 ]

        SOLR-7508: SolrParams.toMultiMap() does not handle arrays

        Show
        ASF subversion and git services added a comment - Commit 1679494 from Noble Paul in branch 'dev/trunk' [ https://svn.apache.org/r1679494 ] SOLR-7508 : SolrParams.toMultiMap() does not handle arrays
        Hide
        ASF subversion and git services added a comment -

        Commit 1679495 from Noble Paul in branch 'dev/branches/branch_5x'
        [ https://svn.apache.org/r1679495 ]

        SOLR-7508: SolrParams.toMultiMap() does not handle arrays

        Show
        ASF subversion and git services added a comment - Commit 1679495 from Noble Paul in branch 'dev/branches/branch_5x' [ https://svn.apache.org/r1679495 ] SOLR-7508 : SolrParams.toMultiMap() does not handle arrays

          People

          • Assignee:
            Noble Paul
            Reporter:
            Thomas Scheffler
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development