Solr
  1. Solr
  2. SOLR-1823

XMLWriter throws ClassCastException on writing maps other than <String,?>

    Details

      Description

      http://lucene.apache.org/solr/api/org/apache/solr/response/SolrQueryResponse.html#returnable_data says that a Map "containing any of the items in this list" may be contained in a SolrQueryResponse and will be handled by QueryResponseWriters.

      This is not true for (at least) Keys in Maps.
      XMLWriter tries to cast keys to Strings.

      1. SOLR-1823.patch
        1 kB
        Frank Wesemann

        Activity

        Hide
        Frank Wesemann added a comment -

        This patch uses String.valueOf( entry.getKey ) to write an entry's key.
        It therefore could not fail.

        Show
        Frank Wesemann added a comment - This patch uses String.valueOf( entry.getKey ) to write an entry's key. It therefore could not fail.
        Hide
        Hoss Man added a comment -

        Nice catch Frank.

        FWIW: the original intent was that any of those types of objects could be used as the value of a Map, not the key – but that's still no excuse to just cast the key instead of using stringification (i could have sworn it was already doing that)

        The one subtlety that your patch broke however is that if someone uses null as a key in the Map, that has always been written out as an entry w/o a key – but by using String.valueOf your patch allways produces a non-null string value (ie: the 4 character string "null") so i modified your patch to just use toString() with an explicit null check.

        Committed revision 925031.

        Show
        Hoss Man added a comment - Nice catch Frank. FWIW: the original intent was that any of those types of objects could be used as the value of a Map, not the key – but that's still no excuse to just cast the key instead of using stringification (i could have sworn it was already doing that) The one subtlety that your patch broke however is that if someone uses null as a key in the Map, that has always been written out as an entry w/o a key – but by using String.valueOf your patch allways produces a non-null string value (ie: the 4 character string "null") so i modified your patch to just use toString() with an explicit null check. Committed revision 925031.
        Hide
        Hoss Man added a comment -

        Correcting Fix Version based on CHANGES.txt, see this thread for more details...

        http://mail-archives.apache.org/mod_mbox/lucene-dev/201005.mbox/%3Calpine.DEB.1.10.1005251052040.24672@radix.cryptio.net%3E

        Show
        Hoss Man added a comment - Correcting Fix Version based on CHANGES.txt, see this thread for more details... http://mail-archives.apache.org/mod_mbox/lucene-dev/201005.mbox/%3Calpine.DEB.1.10.1005251052040.24672@radix.cryptio.net%3E
        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

          People

          • Assignee:
            Hoss Man
            Reporter:
            Frank Wesemann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development