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. |