[JIRA] (JENKINS-49732) java.util.LinkedHashMap$Entry not serializable in Pipeline

2 views
Skip to first unread message

andrew.bayer@gmail.com (JIRA)

unread,
Feb 27, 2018, 3:49:04 PM2/27/18
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
 
Jenkins / Bug JENKINS-49732
java.util.LinkedHashMap$Entry not serializable in Pipeline
Change By: Andrew Bayer
Summary: Cannot pass variable to checkout step locations java.util.LinkedHashMap$Entry not serializable in Pipeline
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Feb 27, 2018, 3:52:17 PM2/27/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-49732
 
Re: java.util.LinkedHashMap$Entry not serializable in Pipeline

So the problem, as Oleg Nenashev noted, is a serialization failure for java.util.LinkedHashMap$Entry. You can reproduce this minimally as follows:

def remote_watch_urls = [
    './branches': 'my url/branches', 
    './releases': 'my url/releases'
    ]
for (foo in remote_watch_urls) {
  sleep 1
  echo "foo is ${foo}"
}

The sleep will trigger Pipeline serialization and things blow up there. I'm not sure if we'll ever be able to actually fix that particular syntax, but there's a trivial workaround:

remote_watch_urls.each { foo ->
  sleep 1
  echo "foo is ${foo}"
}

...should work with no errors.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 27, 2018, 3:52:20 PM2/27/18
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
Change By: Andrew Bayer
Component/s: workflow-cps-plugin
Component/s: pipeline

mdealer@gmail.com (JIRA)

unread,
Mar 1, 2018, 1:29:03 AM3/1/18
to jenkinsc...@googlegroups.com
Edgars Batna commented on Bug JENKINS-49732
 
Re: java.util.LinkedHashMap$Entry not serializable in Pipeline

The workaround helps.

Even if not soon, it should be looked at, get fixed or get a better error message. The latter would be a time-saver.

murashandme@gmail.com (JIRA)

unread,
Jul 5, 2019, 5:27:03 AM7/5/19
to jenkinsc...@googlegroups.com

Hi Andrew Bayer,

It will be very helpful, if you explain why your workaround with groovy closure will work, because I've tried to debug similar code and can see java.util.LinkedHashMap$Entry variables as well.

Does serialization works in different way for variables in closures?

Thanks in advance!

 

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

murashandme@gmail.com (JIRA)

unread,
Jul 10, 2019, 10:28:01 AM7/10/19
to jenkinsc...@googlegroups.com
Ulad Muraveika edited a comment on Bug JENKINS-49732
Hi [~abayer],


It will be very helpful, if you explain why your workaround with groovy closure will work, because I've tried to debug similar code and can see {{java.util.LinkedHashMap$Entry}} variables as well.

Does serialization works in different way for variables in closures?


My answer: yes, it is working different and it can be used as workaround per fixed https://issues.jenkins-ci.org/browse/JENKINS-26481

Thanks in advance!

 

fabian.holler@simplesurance.de (JIRA)

unread,
Nov 12, 2019, 9:11:03 AM11/12/19
to jenkinsc...@googlegroups.com

Does it mean the workaround using `.each` instead does not work anymore since JENKINS-26481?

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

murashandme@gmail.com (JIRA)

unread,
Nov 12, 2019, 10:05:03 AM11/12/19
to jenkinsc...@googlegroups.com

Fabian Holler, please use my small cheat sheet below for all fine points in the pipelines code. Quick answer - you can use .each due to closed JENKINS-26481(https://issues.jenkins-ci.org/browse/JENKINS-26481)

Example of code Can it be used in the pipeline code?
Iterator from plain C-style for-loop Yes
Iterator from Groovy each - JENKINS-26481(https://issues.jenkins-ci.org/browse/JENKINS-26481) Yes
Java 5-style for loop for (data_type item : collection) - JENKINS-27421(https://issues.jenkins-ci.org/browse/JENKINS-27421) Yes
*WARNING - if you are using : Java 5-style for loop for (data_type item : collection) for ANY implementation of Map interface - and want to work with Map Entries you will have java.io.NotSerializableException - java.util.LinkedHashMap$Entry - JENKINS-49732(https://issues.jenkins-ci.org/browse/JENKINS-49732).
Fix will be to use groovy each data.each closure or use visibly entrySet with Java for loop for (def foo : data.entrySet())
No
Any code connected with a regex like code - find, replace, split, groovy syntax sugar =~ and ==~, because all of them have non Serializable java.util.regex.Matcher inside No
JSONSlupper with groovy.json.internal.LazyMap inside. Please use groovy.json.JsonSlurperClassic with java.util.HashMap instead or better use [builtin Jenkins step ](https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readjson-read-json-from-files-in-the-workspace) - readJSON No

fabian.holler@simplesurance.de (JIRA)

unread,
Nov 12, 2019, 10:09:02 AM11/12/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages