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

ClassCastExceptions in o.a.s.request.json.ObjectUtil for valid JSON inputs that are not objects


    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 7.5, master (9.0)
    • Fix Version/s: None
    • Component/s: Server
    • Labels:
    • Environment:


      Requesting any of the following URLs gives a 500 error due to a ClassCastException in o.a.s.r.j.ObjectUtil.mergeObjects:

      The error response is caused by uncaught ClassCastExceptions, such as (for the first URL):

      {{ java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map}}
      at org.apache.solr.request.json.ObjectUtil.mergeObjects(ObjectUtil.java:108)
      at org.apache.solr.request.json.RequestUtil.mergeJSON(RequestUtil.java:269)
      at org.apache.solr.request.json.RequestUtil.processParams(RequestUtil.java:180)
      at org.apache.solr.util.SolrPluginUtils.setDefaults(SolrPluginUtils.java:167)
      at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:196)

      The culprit seems to be the o.a.s.r.j.RequestUtil.mergeJSON method, in particular the following fragment:
              Object o = ObjectBuilder.fromJSON(jsonStr);
              // zero-length strings or comments can cause this to be null (and a zero-length string can result from a json content-type w/o a body)
              if (o != null) {
                ObjectUtil.mergeObjects(json, path, o, handler);

      Note that o is an Object representing a JSON value, while SOLR seems to expect that o holds a JSON object. But in the examples above, the JSON value is a number (represented by  a Long object) instead - this is, in fact, valid JSON.

      A possible fix could be to use the getObject method of ObjectUtil instead of blindly calling fromJSON.

      This bug was found using Diffblue Microservices Testing. Find more information on this test campaign.


        1. home.zip
          376 kB
          Johannes Kloos

          Issue Links



              • Assignee:
                jkloos Johannes Kloos
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: