Copy Java object variable to external process



I have a problem with a java object variable(java.util.ArrayList) that is passed to two external process with call activity tasks, in each called process I need to add specific elements on this array. The problem is when I add a element in a process via a script the arrays in the other processes get updated as well, as if the variable is a reference to the object in the parent process instance instead of a copy. I tried setting the variable with execution.setVariableLocal but I got the same behaivor

Here are the processes that I am using for testing

proc1.bpmn (3.1 KB)
proc0.bpmn (9.0 KB)
proc2.bpmn (3.1 KB)

Once the processes are called I need to have these value in the array in each process
proc0 [[name:“a”],[name:“b”]]
proc1 [[name:“a”],[name:“b”],[name:“process1”]]
proc2 [[name:“a”],[name:“b”],[name:“process2”]]

Instead I get [[name:“a”],[name:“b”],[name:“process1”],[name:“process2”]] in each process

“a” and “b” are added in proc0
“process1” is added in proc1
“process2” is added in proc2


hi @diedu89,
would creating a shallow copy of the list you provide in proc0.bpmn and setting this copy by execution.setVariableLocal() at each of the called subprocesses solve your problem?

to understate how variable scopes and variable visibilty work with camunda, this link might help.