ConcurrentModificationException during CpsThreadGroup.saveProgram

68 views
Skip to first unread message

Ullrich Hafner

unread,
Nov 15, 2018, 5:50:42 AM11/15/18
to Jenkins Developers
I sometimes get in my integration tests of pipeline builds with my warnings steps a ConcurrentModificationException during CpsThreadGroup.saveProgram.

How can this happen? Do I need to take care of synchronization somewhere?

an exception which occurred:
in field edu.hm.hafner.analysis.Report.infoMessages
in object edu.hm.hafner.analysis.Report@105859bf
in field io.jenkins.plugins.analysis.core.steps.AnnotatedReport.aggregatedReport
in object io.jenkins.plugins.analysis.core.steps.AnnotatedReport@274c5b82
in field io.jenkins.plugins.analysis.core.steps.PublishIssuesStep$Execution.report
in object io.jenkins.plugins.analysis.core.steps.PublishIssuesStep$Execution@25f0dc81
in field org.jenkinsci.plugins.workflow.cps.CpsThread.step
in object org.jenkinsci.plugins.workflow.cps.CpsThread@7cf8c376
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@9df7d3c
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@9df7d3c
Caused: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
at java.util.ArrayList$Itr.next(ArrayList.java:859)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:568)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
at java.util.TreeMap.writeObject(TreeMap.java:2438)
at sun.reflect.GeneratedMethodAccessor76.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:140)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:459)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:435)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:423)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:363)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Jesse Glick

unread,
Nov 15, 2018, 5:25:01 PM11/15/18
to jenkin...@googlegroups.com
Do you have some background thread writing to `infoMessages` perhaps?

Ullrich Hafner

unread,
Feb 8, 2019, 9:28:36 AM2/8/19
to Jenkins Developers

I'm not aware of any. When is CpsThreadGroup.saveProgram called? During execution of SynchronousNonBlockingStepExecution.run() ?
Should members of a  SynchronousNonBlockingStepExecution be constant?

Jesse Glick

unread,
Feb 8, 2019, 3:00:33 PM2/8/19
to Jenkins Dev
Am Donnerstag, 15. November 2018 23:25:01 UTC+1 schrieb Jesse Glick:
>> Do you have some background thread writing to `infoMessages` perhaps?

On Fri, Feb 8, 2019 at 9:28 AM Ullrich Hafner <ullrich...@gmail.com> wrote:
> I'm not aware of any.

Trying wrapping all field accessors in `Collections.immutableList` and
you will find out fast!

> When is CpsThreadGroup.saveProgram called?

At various times, though always within the CPS VM thread.

> During execution of SynchronousNonBlockingStepExecution.run() ?

Not from that thread.

> Should members of a SynchronousNonBlockingStepExecution be constant?

They need not be; if you need to mutate anything, use

https://javadoc.jenkins.io/plugin/workflow-step-api/org/jenkinsci/plugins/workflow/steps/StepContext.html#saveState--

But you do need to consider that the CPS VM thread may be _reading_
that state, so you may consider replacing `ArrayList` with
`CopyOnWriteList` for example.
Reply all
Reply to author
Forward
0 new messages