[JIRA] (JENKINS-37629) java.io.NotSerializableException: groovy.json.internal.LazyMap error

968 views
Skip to first unread message

deep.anu98@yahoo.co.in (JIRA)

unread,
Aug 23, 2016, 10:45:06 AM8/23/16
to jenkinsc...@googlegroups.com
Anudeep Lalam created an issue
 
Jenkins / Bug JENKINS-37629
java.io.NotSerializableException: groovy.json.internal.LazyMap error
Issue Type: Bug Bug
Assignee: Oleg Nenashev
Components: pipeline-_unsorted
Created: 2016/Aug/23 2:44 PM
Priority: Blocker Blocker
Reporter: Anudeep Lalam

Hi,
When I use below method after parsing the JSON using JsonSlurper(), I am getting java.io.NotSerializableException: groovy.json.internal.LazyMap error.
If I just try to print the values of the JSON, I am not getting any error

Can someone please share the workaround for this. This is a blocker for us.

def gitCheckOut(String wsPath, String url, String cred, String branch) {
	try {
		ws("$wsPath") {
			git ([url: "$url", credentialsId: "$cred", branch: "$branch"])
		}
	} catch (Exception ex) {
		echo ex.getMessage()
		gitCoErrors = gitCoErrors + "$wsPath\n"
	}
}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

deep.anu98@yahoo.co.in (JIRA)

unread,
Aug 23, 2016, 10:56:02 AM8/23/16
to jenkinsc...@googlegroups.com
Anudeep Lalam updated an issue
Change By: Anudeep Lalam
Hi,
When I use below method after parsing the JSON using *JsonSlurper()*, I am getting {color:red}java.io.NotSerializableException: groovy.json.internal.LazyMap {color}error.

If I just try to print the values of the JSON, I am not getting any error

Can someone please share the workaround for this. This is a blocker for us.

{code}

def gitCheckOut(String wsPath, String url, String cred, String branch) {
try {
  ws("$wsPath") {
   git ([url: "$url", credentialsId: "$cred", branch: "$branch"])
  }
} catch (Exception ex) {
  echo ex.getMessage()
  gitCoErrors = gitCoErrors + "$wsPath\n"
}
}

node("HOST1")
{
gitCheckOut("$unixws","$gitUrl","gitCred","$gitBranch")
}

{
code}

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 23, 2016, 11:00:01 AM8/23/16
to jenkinsc...@googlegroups.com
Oleg Nenashev updated an issue
Change By: Oleg Nenashev
Component/s: workflow-plugin
Component/s: pipeline-_unsorted

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 23, 2016, 11:06:01 AM8/23/16
to jenkinsc...@googlegroups.com
Oleg Nenashev commented on Bug JENKINS-37629
 
Re: java.io.NotSerializableException: groovy.json.internal.LazyMap error

Pipeline plugin saves the context after each operation in order to be tolerant against Jenkins restarts.
In your case the code returns a non-serializable object, hence it cannot work. I'm not sure what is the code is, because the provided example is irrelevant from what I see.

In order to solve the issue, you should move all operations with this object to a method and annotate this method with @NonCPS . It is described here: https://support.cloudbees.com/hc/en-us/articles/204972960-The-pipeline-even-if-successful-ends-with-java-io-NotSerializableException

See also: http://stackoverflow.com/questions/36636017/jenkins-groovy-how-to-call-methods-from-noncps-method-without-ending-pipeline

deep.anu98@yahoo.co.in (JIRA)

unread,
Aug 23, 2016, 11:28:02 AM8/23/16
to jenkinsc...@googlegroups.com
Anudeep Lalam commented on Bug JENKINS-37629
 
Re: java.io.NotSerializableException: groovy.json.internal.LazyMap error

Hi Oleg Nenashev,

Thanks for your reply. This is my scenario. I have my GIT url, credentials etc in a JSON file. I am parsing the JSON and passing the values to a gitCheckOut method.

Please see below code.

In the below code, I am successfully able to read the values form JSON file and even able to print them. But the script is throwing the error at node("HOST1") step. When I remove this step it works. So, can you please tell me what needs to be done.

variables = parseText(new File('/Build/variables.json').text)
platforms = parseText(new File('Build/platforms.json').text)
	
def parseText(txt){
    return new groovy.json.JsonSlurper().parseText(txt)
}

gitUrl = variables.git.url
gitCred = variables.git.credential
gitBranch = variables.git.branch
unixws = variables.ws.unix

def gitCheckOut(String wsPath, String url, String cred, String branch) {
	
try {
		ws("$wsPath") {
			git ([url: "$url", credentialsId: "$cred", branch: "$branch"])
		}
	} catch (Exception ex) {
		echo ex.getMessage()
		gitCoErrors = gitCoErrors + "$wsPath\n"
	}
}


node("HOST1") {
	gitCheckOut("$unixws","$gitUrl","gitCred","$gitBranch")
}

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 23, 2016, 11:47:01 AM8/23/16
to jenkinsc...@googlegroups.com
Oleg Nenashev commented on Bug JENKINS-37629
 
Re: java.io.NotSerializableException: groovy.json.internal.LazyMap error

So you need to...
1) Annotate parseText() as NonCPS
2) Within the method convert the returned data object to a serializable collection. Then return it from the method

jglick@cloudbees.com (JIRA)

unread,
Aug 26, 2016, 1:46:02 PM8/26/16
to jenkinsc...@googlegroups.com
Jesse Glick commented on Bug JENKINS-37629
 
Re: java.io.NotSerializableException: groovy.json.internal.LazyMap error

Duplicate of something, do not have time to look it up right now. JsonSlurper is known not to work.

deep.anu98@yahoo.co.in (JIRA)

unread,
Aug 26, 2016, 3:13:02 PM8/26/16
to jenkinsc...@googlegroups.com
Anudeep Lalam commented on Bug JENKINS-37629
 
Re: java.io.NotSerializableException: groovy.json.internal.LazyMap error

Oleg Nenashev, Jesse Glick : Thanks for your time in looking into this issue. My issue got resolved. After surfing a lot over web, I could resolve it by using JsonSlurperClassic instead of JsonSlurper.

I am not exactly sure what's the difference between both but JsonSlurperClassic works

This issue can be closed.

Thanks Again!

deep.anu98@yahoo.co.in (JIRA)

unread,
Aug 26, 2016, 3:14:01 PM8/26/16
to jenkinsc...@googlegroups.com
Anudeep Lalam closed an issue as Fixed
Change By: Anudeep Lalam
Status: Open Closed
Resolution: Fixed
Reply all
Reply to author
Forward
0 new messages