AnsweredAssumed Answered

Behavior of Multi Instance Tasks/Subprocesses on emtpy collections

Question asked by jakobtonn on Dec 2, 2014
Latest reply on Feb 27, 2015 by gi00vani_kun
In the application we are currently developing, we have the scenario of a multi-instance subprocesses which has a collection that might be empty. Our expectation was that if the collection was empty, Activiti would just skip the sub-process altogether and continue the execution after the sub-process, same as e.g. Java would execute a for-each-loop on an empty collection. Instead, we found out that Actviti 5.17.0-SNAPSHOT will throw an exception like this:


org.activiti.engine.ActivitiIllegalArgumentException: Invalid number of instances: must be positive integer value, but was 0
   at org.activiti.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.createInstances(ParallelMultiInstanceBehavior.java:41)
   at org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.execute(MultiInstanceActivityBehavior.java:90)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
        …

Older versions will throw an NPE instead at this point, so I guess this exception was introduced in 5.17.0-SNAPSHOT.

My question is, is there any reason why this exception is thrown instead of just skipping the multi instance activity (which would still fulfill the specification of creating an instance for each element of the collection) and continue the process after it? If not, I could prepare a pull request to change this behavior to our expectations.

Outcomes