VariableLocal / Execution with and without error boundary event

Hi,

I have a question regarding the usage of setVariableLocal.

I have the following sub process that is being started by a parent process instance (multi-instance call activity).

Source code of example tasks:

@Component
public class SetVariableLocalDelegate implements JavaDelegate {
	private static final Logger LOG = LoggerFactory.getLogger(SetVariableLocalDelegate.class);
	 
	@Override
	public void execute(DelegateExecution execution) throws Exception {
		String varName = "condition";
		String value = "one";
		
		execution.setVariableLocal(varName, value);

		LOG.info("Set variable local {} = {}", varName, value);
	}
}

@Component
public class LogDelegate implements JavaDelegate {
	private static final Logger LOG = LoggerFactory.getLogger(LogDelegate.class);
	
	@Override
	public void execute(DelegateExecution execution) throws Exception {
		LOG.info("getVariable condition = {}", (String) execution.getVariable("condition"));
		
		LOG.info("getVariableLocal condition = {}", (String) execution.getVariableLocal("condition"));
	}
}


local-ohne-error-boundary-mit-listener.bpmn (10.1 KB)
Modeled this way the ‘condition’ variable works as expected: It is set as variable local then being evaluated and the correct service task is being executed.

However after we decided to attach an interrupting boundary error event to the first service task that sets the local variable ‘condition’ the execution did not work anymore.


local-mit-error-boundary-mit-listener.bpmn (11.3 KB)

To investigate this we included execution listeners to the model (the modeler plugin shows those as a little green ‘L’).

Now the surprising comparison of both process models is shown below:

Execution without boundary event

service task setVariableLocal start: execution.id: 900df601-d586-11eb-8094-9498a4515e53
2021-06-25 09:25:48.426  INFO 12168 --- [aTaskExecutor-2] nt.delegate.SetVariableLocalDelegate     : Set variable local condition = one
service task setVariableLocal end: execution.id: 900df601-d586-11eb-8094-9498a4515e53
flow to gw: take: execution.id: 900df601-d586-11eb-8094-9498a4515e53
gateway start: execution.id: 900df601-d586-11eb-8094-9498a4515e53
gateway end: execution.id: 900df601-d586-11eb-8094-9498a4515e53
one flow take: execution.id: 900df601-d586-11eb-8094-9498a4515e53
service task do one start: execution.id: 900df601-d586-11eb-8094-9498a4515e53
2021-06-25 09:25:48.438  INFO 12168 --- [aTaskExecutor-2] nt.delegate.LogDelegate                  : getVariable condition = one
2021-06-25 09:25:48.438  INFO 12168 --- [aTaskExecutor-2] nt.delegate.LogDelegate                  : getVariableLocal condition = one
service task do one end: execution.id: 900df601-d586-11eb-8094-9498a4515e53

Execution with boundary event. two different executions! Does not work anymore

service task setVariableLocal start: execution.id: c2c227c9-d586-11eb-8094-9498a4515e53
2021-06-25 09:27:13.479  INFO 12168 --- [aTaskExecutor-3] nt.delegate.SetVariableLocalDelegate     : Set variable local condition = one
service task setVariableLocal end: execution.id: c2c227c9-d586-11eb-8094-9498a4515e53
flow to gw: take: execution.id: c2c07a12-d586-11eb-8094-9498a4515e53
gateway start: execution.id: c2c07a12-d586-11eb-8094-9498a4515e53
2021-06-25 09:27:13.486 ERROR 12168 --- [aTaskExecutor-3] org.camunda.bpm.engine.context           : ENGINE-16004 Exception while closing command context: Unknown property used in expression: ${'one' eq condition}. Cause: Cannot resolve identifier 'condition'

org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${'one' eq condition}. Cause: Cannot resolve identifier 'condition'

It seems that the whole execution tree changes.

My question is: Is there any sort of rule of thumb to foresee changes like this and
how should I use the setVariableLocal method in a context like this?
Thanks!

Hello @d_c ,

welcome to our forum! :slight_smile:

First, you do not need to set this variable local, as the variable mapping in a call activity is done explicitely.

Second, a boundary event is something that can happen during the task it is attached to is waiting, so there is an additional state.

What I can recommend is being careful when using local variable scopes.
Usually, what I do is either using the scope of a task OR the scope of my process.

Hope this helps

Jonathan