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

SolrJ ClassCastException on XML /suggest requests

    XMLWordPrintableJSON

    Details

    • Type: Task
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 8.6.3, main (9.0)
    • Fix Version/s: 8.8, main (9.0)
    • Component/s: SolrJ, Suggester
    • Labels:
      None

      Description

      SolrJ throws a ClassCastException when parsing XML /suggest responses.

      The following code snippet (run against the techproduct example) produces the stack trace that follows:

        public void testSuggestFailure() throws Exception {
      
          HttpSolrClient client = new HttpSolrClient.Builder()
              .withBaseSolrUrl("http://localhost:8983/solr/techproducts")
              .withResponseParser(new XMLResponseParser())
              .build();
      
          Map<String, String> queryParamMap = new HashMap<>();
          queryParamMap.put("qt", "/suggest");
          queryParamMap.put("suggest.q", "elec");
          queryParamMap.put("suggest.build", "true");
          queryParamMap.put("suggest", "true");
          queryParamMap.put("suggest.dictionary", "mySuggester");
          queryParamMap.put("wt", "xml");
          QueryResponse resp = client.query(new MapSolrParams(queryParamMap));
        }
      
      java.lang.ClassCastException: class org.apache.solr.common.util.SimpleOrderedMap cannot be cast to class java.util.Map (org.apache.solr.common.util.SimpleOrderedMap is in unnamed module of loader 'app'; java.util.Map is in module java.base of loader 'bootstrap')
          at org.apache.solr.client.solrj.response.QueryResponse.setResponse(QueryResponse.java:170) ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan - 2020-01-10 13:40:30]
          at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:211) ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan - 2020-01-10 13:40:30]
          at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:1003) ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan - 2020-01-10 13:40:30]
          at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:1018) ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan - 2020-01-10 13:40:30]
      

      SolrJ's QueryResponse expects the "suggest" section in the NamedList response to be a Map - and for requests that use javabin (the default ResponseParser), it is. But when parsing XML responses the "suggest" section deserialized as a SimpleOrderedMap (which despite the name doesn't implement Map).

      The root cause afaict is that SuggestComponent uses a type (HashMap) that serializes/deserializes differently based on the codec/wt used on the wire. JavaBinCodec has special handling for maps that our XML serialization doesn't have, so the two produce different response structures on the client side.

      The "right" fix here is to change SuggestComponent's response to only use types that serialize/deserialize identically in all SolrJ's ResponseParser's. This is a breaking change though - a SolrJ user making /suggest requests, getting the responses via javavbin, and inspecting the resulting NamedList directly would get a different object tree after this fix than they would've before. So an 8.x fix would need to take a different approach.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gerlowskija Jason Gerlowski
                Reporter:
                gerlowskija Jason Gerlowski
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 40m
                  1h 40m