[JIRA] (JENKINS-40514) Typing Return Value of readMavenPom Causes ClassCastException

140 views
Skip to first unread message

tim.eapen@gmail.com (JIRA)

unread,
Dec 16, 2016, 10:42:03 AM12/16/16
to jenkinsc...@googlegroups.com
Tim Eapen created an issue
 
Jenkins / Bug JENKINS-40514
Typing Return Value of readMavenPom Causes ClassCastException
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2016/Dec/16 3:41 PM
Priority: Minor Minor
Reporter: Tim Eapen
import org.apache.maven.model.Model

Model mavenProject = readMavenPom(file: pom)

The above groovy script causes a ClassCastException when executing a Pipeline script:

[Pipeline] echo
Marking build as failure due to the following error: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.rbc.rbcone.shared.authorization:rbcone-shared-authorization-api:jar:0.6.1-201612151515.0777507' with class 'org.apache.maven.model.Model' to class 'org.apache.maven.model.Model'
[Pipeline] stage
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

tim.eapen@gmail.com (JIRA)

unread,
Dec 16, 2016, 10:43:02 AM12/16/16
to jenkinsc...@googlegroups.com
Tim Eapen updated an issue
Change By: Tim Eapen
{code:java}

import org.apache.maven.model.Model

Model mavenProject = readMavenPom(file: pom)
{code}


The above groovy script causes a ClassCastException when executing a Pipeline script:

{code:java}
[Pipeline] echo
Marking build as failure due to the following error: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.
rbc.rbcone.shared.authorization foo : rbcone bar - shared-authorization- api:jar:0.6.1-201612151515.0777507' with class 'org.apache.maven.model.Model' to class 'org.apache.maven.model.Model'
[Pipeline] stage
{code}

tim.eapen@gmail.com (JIRA)

unread,
Dec 16, 2016, 10:49:03 AM12/16/16
to jenkinsc...@googlegroups.com
Tim Eapen commented on Bug JENKINS-40514
 
Re: Typing Return Value of readMavenPom Causes ClassCastException

Stacktrace for the above error:

hudson.remoting.ProxyException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.foo:bar-api:jar:0.6.1-201612161044.0777507' with class 'org.apache.maven.model.Model' to class 'org.apache.maven.model.Model'
	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 maven.purgeLocalRepository(/var/jenkins_home/jobs/rbcone-shared-authorization-api/branches/master/builds/16/libs/commons/vars/maven.groovy:9)
	at WorkflowScript.cleanup(WorkflowScript:33)
	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)
	at sun.reflect.GeneratedMethodAccessor288.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.Outcome.resumeFrom(Outcome.java:73)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:324)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:78)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:224)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

tim.eapen@gmail.com (JIRA)

unread,
Dec 16, 2016, 10:49:03 AM12/16/16
to jenkinsc...@googlegroups.com
Tim Eapen edited a comment on Bug JENKINS-40514
Stacktrace for the above error : .  Lookse like the DefautlTypeTransformation class cannot cast the return object properly.


{code:java}
{code}

medy.belmokhtar@gmail.com (JIRA)

unread,
Dec 22, 2016, 11:29:01 AM12/22/16
to jenkinsc...@googlegroups.com

Same issue

jenkins 2.37, Pipeline 2.4 and Pipeline Utility Steps 1.2.2

sascha@akv-soft.de (JIRA)

unread,
Jan 17, 2017, 1:25:02 AM1/17/17
to jenkinsc...@googlegroups.com

Ditto with Jenkins 2.19.1, Pipeline 2.4 and Pipeline Utility Steps 1.2.2

It used to work though with 2.19.1, Pipeline 2.4 and Pipeline Utility Steps 1.1.6

andrew.bayer@gmail.com (JIRA)

unread,
Mar 21, 2017, 2:00:01 PM3/21/17
to jenkinsc...@googlegroups.com

This sounds like http://stackoverflow.com/questions/34068168/groovy-binding-cannot-cast-object-with-class-custompackage-customclass-to-cla - could you try doing def mavenProject = readMavenPom(file: pom) instead of Model mavenProject ... and see if that helps?

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

jglick@cloudbees.com (JIRA)

unread,
Mar 21, 2017, 2:23:02 PM3/21/17
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
 
Change By: Jesse Glick
Component/s: pipeline-utility-steps-plugin
Component/s: pipeline

jglick@cloudbees.com (JIRA)

unread,
Mar 21, 2017, 2:27:02 PM3/21/17
to jenkinsc...@googlegroups.com
Jesse Glick commented on Bug JENKINS-40514
 
Re: Typing Return Value of readMavenPom Causes ClassCastException

Perhaps some other plugin is also loading maven-core. Probably maven-plugin.

I would not recommend importing org.apache.maven.model.* classes; use dynamic typing.

Or just avoid the readMavenPom step altogether, and use something like

def version = sh script: '''
mvn help:evaluate -Dexpression=project.version | perl -n -e 'print $1 if /^([0-9.]+(-SNAPSHOT)?)$/'
''', returnStdout: true

reitzmichnicht@gmx.de (JIRA)

unread,
Jun 29, 2018, 3:49:02 AM6/29/18
to jenkinsc...@googlegroups.com

I have the same problem. def mavenProject works, but Model mavenProject throws the same exception.

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

fabrice.pipart@gmail.com (JIRA)

unread,
Jul 3, 2018, 4:29:01 AM7/3/18
to jenkinsc...@googlegroups.com

Same too. This does not help writing libraries with proper type checks. Anyone has an idea for a fix or a workaround?

jglick@cloudbees.com (JIRA)

unread,
Jul 20, 2018, 3:43:01 PM7/20/18
to jenkinsc...@googlegroups.com

My advice remains to avoid these two steps.

jglick@cloudbees.com (JIRA)

unread,
Jul 20, 2018, 3:52:02 PM7/20/18
to jenkinsc...@googlegroups.com

Filed a PR to formally deprecate these steps.

fabrice.pipart@gmail.com (JIRA)

unread,
Jul 21, 2018, 6:37:02 AM7/21/18
to jenkinsc...@googlegroups.com

Hi!

Which two steps are you refering to?

I definitely prefer

import org.apache.maven.model.Model Model mavenProject = readMavenPom(file: pom)

over

mvn help:evaluate -Dexpression=project.version | perl -n -e 'print $1 if /^([0-9.]+(-SNAPSHOT)?)$/' ''', returnStdout: true

It is more reliable, more readable and does not require (like any maven plugin execution) a lot of network activity in order to download / check all dependencies.
I have to admit, though, that I am OK to keep dynamic typing. It is just that it looks more like a bug that you avoid than something that you really want.

Reply all
Reply to author
Forward
0 new messages