Scenario
We have a Process with an event sub process, which has an non-interrupting conditional start event. If a process instance is started with a set of variables, which satisfy the condition, then the event process is triggered depending on the count of variables + 1.
Example
You start the process instance with three variables then the event process is triggered four times. You can use the following test case to reproduce this behavior.
@Test
@Deployment(resources ={ "org/camunda/bpm/engine/test/bpmn/event/conditional/EventSubProcessStartConditionalEventTest.testNonInterruptingVariableCondition.bpmn20.xml"})
public void testNonInterruptingVariableConditionSetVariableOnStart() {
//given process with event sub process conditional start event
final VariableMap variables = Variables.createVariables();
variables.putValue(VARIABLE_NAME, 1);
variables.putValue("foo", 1);
variables.putValue("bar", 1);
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY, variables);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
//then execution is at user task after conditional start event
tasksAfterVariableIsSet = taskQuery.list();
assertEquals(2, tasksAfterVariableIsSet.size());
assertEquals(1, conditionEventSubscriptionQuery.list().size());
}
Observed behavior
The event process is first triggered in PvmAtomicOperationProcessStart#eventNotificationsCompleted, since
#continueIfExecutionDoesNotAffectNextOperation will trigger this conditional event.
The variables are also being stored as delayed variables and evaluated afterwards on the next #dispatchDelayedEventsAndPerformOperation. Since the condition is always true, because the variable is in the scope to satisfy the condition, the event sub process is started as many times as variables are given at start.