Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49985

hudson.remoting.ProxyException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{"labels":{"Verified":1}}' with class 'com.google.gson.JsonObject' to class 'com.google.gson.JsonElement'

    Details

    • Similar Issues:
    • Released As:
      gerrit-code-review-0.2

      Description

      Error while trying to add Verified label to Gerrit.

      hudson.remoting.ProxyException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{"labels":{"Verified":1}}' with class 'com.google.gson.JsonObject' to class 'com.google.gson.JsonElement'
      	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
      	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
      	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
      	at Unknown.Unknown(Unknown)
      	at jenkins.plugins.gerrit.workflow.Gerrit.post(jar:file:/var/lib/jenkins/plugins/gerrit/WEB-INF/lib/gerrit.jar!/jenkins/plugins/gerrit/workflow/Gerrit.groovy:69)
      	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2030)
      	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2015)
      	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2056)
      	at jenkins.plugins.gerrit.workflow.Gerrit.post(jar:file:/var/lib/jenkins/plugins/gerrit/WEB-INF/lib/gerrit.jar!/jenkins/plugins/gerrit/workflow/Gerrit.groovy:66)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.set(LocalVariableBlock.java:45)
      	at com.cloudbees.groovy.cps.impl.AssignmentBlock$ContinuationImpl.assignAndDone(AssignmentBlock.java:70)
      

        Attachments

          Activity

          Hide
          eisakson Eric Isakson added a comment -

          This smelled like a classloader issue, so I added some diagnostics in my local version to help track down what is happening. I'm still really new to Jenkins plugin development, so I don't really understand what the root cause or correct fix should be but it looks like this is a bad interaction between the new plugin and the old gerrit-trigger plugin, look at the jars on the AntClassLoader for JsonObject and JsonElement which are from the gerrit-trigger plugin where the result object JsonObject is coming from the gerrit-code-review plugin:

          Class loader hierarchy for class com.google.gson.JsonObject
          [AntClassLoader[/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gson-2.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/oro-2.0.8.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpcore-4.4.4.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/guava-11.0.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-jdk14-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/commons-net-2.0.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-core-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-annotations-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-api-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-databind-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/j2ssh-maverick-1.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jsch-0.1.51.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-trigger.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpclient-4.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-events-2.12.0.jar]] hashCode=863687531
            [hudson.ClassicPluginStrategy$DependencyClassLoader@62f59d1] hashCode=103766481
              [hudson.util.MaskingClassLoader@53f9986f] hashCode=1408866415
                [WebAppClassLoader=Jenkins v2.107.2@4cb2c100] hashCode=1286783232
                  [java.net.URLClassLoader@312b1dae] hashCode=824909230
                    [java.net.URLClassLoader@3f99bd52] hashCode=1067040082
                      [sun.misc.Launcher$AppClassLoader@4aa298b7] hashCode=1252169911
                        [sun.misc.Launcher$ExtClassLoader@4c9f8c13] hashCode=1285524499
          context class loader=[org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader@4aedecc9] hashCode=1257106633
          Class loader hierarchy for class com.google.gson.JsonElement
          [AntClassLoader[/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gson-2.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/oro-2.0.8.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpcore-4.4.4.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/guava-11.0.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-jdk14-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/commons-net-2.0.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-core-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-annotations-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-api-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-databind-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/j2ssh-maverick-1.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jsch-0.1.51.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-trigger.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpclient-4.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-events-2.12.0.jar]] hashCode=863687531
            [hudson.ClassicPluginStrategy$DependencyClassLoader@62f59d1] hashCode=103766481
              [hudson.util.MaskingClassLoader@53f9986f] hashCode=1408866415
                [WebAppClassLoader=Jenkins v2.107.2@4cb2c100] hashCode=1286783232
                  [java.net.URLClassLoader@312b1dae] hashCode=824909230
                    [java.net.URLClassLoader@3f99bd52] hashCode=1067040082
                      [sun.misc.Launcher$AppClassLoader@4aa298b7] hashCode=1252169911
                        [sun.misc.Launcher$ExtClassLoader@4c9f8c13] hashCode=1285524499
          context class loader=[org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader@4aedecc9] hashCode=1257106633
          Showing class loader hierarchy for result of gerritApi.restClient().postRequest(path, jsonPayload)
          Class loader hierarchy for class com.google.gson.JsonObject
          [AntClassLoader[/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/annotation-indexer-1.11.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/bridge-method-annotation-1.17.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/commons-codec-1.9.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/gerrit-code-review.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/gerrit-rest-java-client-0.8.13.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/gson-2.8.2.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/guava-19.0.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/httpclient-4.5.2.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/httpcore-4.4.4.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/joda-time-2.9.5.jar]] hashCode=1625500293
            [hudson.ClassicPluginStrategy$DependencyClassLoader@55303e4e] hashCode=1429225038
              [hudson.util.MaskingClassLoader@53f9986f] hashCode=1408866415
                [WebAppClassLoader=Jenkins v2.107.2@4cb2c100] hashCode=1286783232
                  [java.net.URLClassLoader@312b1dae] hashCode=824909230
                    [java.net.URLClassLoader@3f99bd52] hashCode=1067040082
                      [sun.misc.Launcher$AppClassLoader@4aa298b7] hashCode=1252169911
                        [sun.misc.Launcher$ExtClassLoader@4c9f8c13] hashCode=1285524499
          context class loader=[org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader@4aedecc9] hashCode=1257106633
          

           

          Note that to get this I had to change the line:

                  JsonElement result = gerritApi.restClient().postRequest(path, jsonPayload)
          

           

          to:

                  def result = gerritApi.restClient().postRequest(path, jsonPayload)
          

           

          which also works around the issue since it no longer tries to cast the object.

          Show
          eisakson Eric Isakson added a comment - This smelled like a classloader issue, so I added some diagnostics in my local version to help track down what is happening. I'm still really new to Jenkins plugin development, so I don't really understand what the root cause or correct fix should be but it looks like this is a bad interaction between the new plugin and the old gerrit-trigger plugin, look at the jars on the AntClassLoader for JsonObject and JsonElement which are from the gerrit-trigger plugin where the result object JsonObject is coming from the gerrit-code-review plugin: Class loader hierarchy for class com.google.gson.JsonObject [AntClassLoader[/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gson-2.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/oro-2.0.8.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpcore-4.4.4.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/guava-11.0.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-jdk14-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/commons-net-2.0.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-core-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-annotations-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-api-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-databind-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/j2ssh-maverick-1.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jsch-0.1.51.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-trigger.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpclient-4.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-events-2.12.0.jar]] hashCode=863687531 [hudson.ClassicPluginStrategy$DependencyClassLoader@62f59d1] hashCode=103766481 [hudson.util.MaskingClassLoader@53f9986f] hashCode=1408866415 [WebAppClassLoader=Jenkins v2.107.2@4cb2c100] hashCode=1286783232 [java.net.URLClassLoader@312b1dae] hashCode=824909230 [java.net.URLClassLoader@3f99bd52] hashCode=1067040082 [sun.misc.Launcher$AppClassLoader@4aa298b7] hashCode=1252169911 [sun.misc.Launcher$ExtClassLoader@4c9f8c13] hashCode=1285524499 context class loader=[org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader@4aedecc9] hashCode=1257106633 Class loader hierarchy for class com.google.gson.JsonElement [AntClassLoader[/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gson-2.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/oro-2.0.8.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpcore-4.4.4.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/guava-11.0.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-jdk14-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/commons-net-2.0.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-core-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-annotations-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/slf4j-api-1.6.1.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jackson-databind-2.4.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/j2ssh-maverick-1.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/jsch-0.1.51.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-trigger.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/httpclient-4.5.2.jar:/reps/jenkins/home/plugins/gerrit-trigger/WEB-INF/lib/gerrit-events-2.12.0.jar]] hashCode=863687531 [hudson.ClassicPluginStrategy$DependencyClassLoader@62f59d1] hashCode=103766481 [hudson.util.MaskingClassLoader@53f9986f] hashCode=1408866415 [WebAppClassLoader=Jenkins v2.107.2@4cb2c100] hashCode=1286783232 [java.net.URLClassLoader@312b1dae] hashCode=824909230 [java.net.URLClassLoader@3f99bd52] hashCode=1067040082 [sun.misc.Launcher$AppClassLoader@4aa298b7] hashCode=1252169911 [sun.misc.Launcher$ExtClassLoader@4c9f8c13] hashCode=1285524499 context class loader=[org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader@4aedecc9] hashCode=1257106633 Showing class loader hierarchy for result of gerritApi.restClient().postRequest(path, jsonPayload) Class loader hierarchy for class com.google.gson.JsonObject [AntClassLoader[/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/annotation-indexer-1.11.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/bridge-method-annotation-1.17.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/commons-codec-1.9.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/gerrit-code-review.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/gerrit- rest -java-client-0.8.13.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/gson-2.8.2.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/guava-19.0.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/httpclient-4.5.2.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/httpcore-4.4.4.jar:/reps/jenkins/home/plugins/gerrit-code-review/WEB-INF/lib/joda-time-2.9.5.jar]] hashCode=1625500293 [hudson.ClassicPluginStrategy$DependencyClassLoader@55303e4e] hashCode=1429225038 [hudson.util.MaskingClassLoader@53f9986f] hashCode=1408866415 [WebAppClassLoader=Jenkins v2.107.2@4cb2c100] hashCode=1286783232 [java.net.URLClassLoader@312b1dae] hashCode=824909230 [java.net.URLClassLoader@3f99bd52] hashCode=1067040082 [sun.misc.Launcher$AppClassLoader@4aa298b7] hashCode=1252169911 [sun.misc.Launcher$ExtClassLoader@4c9f8c13] hashCode=1285524499 context class loader=[org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader@4aedecc9] hashCode=1257106633   Note that to get this I had to change the line: JsonElement result = gerritApi.restClient().postRequest(path, jsonPayload)   to: def result = gerritApi.restClient().postRequest(path, jsonPayload)   which also works around the issue since it no longer tries to cast the object.
          Hide
          lucamilanesio Luca Domenico Milanesio added a comment -

          Yes, a PR has been pushed and merged now (see https://github.com/jenkinsci/gerrit-code-review-plugin/pull/11). 

          Show
          lucamilanesio Luca Domenico Milanesio added a comment - Yes, a PR has been pushed and merged now (see https://github.com/jenkinsci/gerrit-code-review-plugin/pull/11).  

            People

            • Assignee:
              lucamilanesio Luca Domenico Milanesio
              Reporter:
              ssbarnea Sorin Sbarnea
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: