Skip to content

NullPointerException in ParallelMultiInstanceBehavior.leave() when completing a user task (execution is null in setLoopVariable) #4184

@austin-2020

Description

@austin-2020

Describe the bug

When completing a parallel multi-instance (会签) user task, the engine throws a NullPointerException because execution is null inside MultiInstanceActivityBehavior.setLoopVariable(), called from ParallelMultiInstanceBehavior.leave().

Stack trace

java.lang.NullPointerException: Cannot invoke "org.flowable.engine.delegate.DelegateExecution.setVariableLocal(String, Object)" because "execution" is null at org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.setLoopVariable(MultiInstanceActivityBehavior.java:579) at org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.leave(ParallelMultiInstanceBehavior.java:296) at org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.internalLeave(ParallelMultiInstanceBehavior.java:233) at org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.leave(ParallelMultiInstanceBehavior.java:174) at org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.leave(AbstractBpmnActivityBehavior.java:60) at org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior.trigger(UserTaskActivityBehavior.java:340) at org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.trigger(MultiInstanceActivityBehavior.java:325) ... at org.flowable.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:236)

Environment

  • Flowable version: 7.2.0
  • Integration: flowable-spring-boot-starter 7.2.0
  • Java: 17
  • Database: PostgreSQL (if relevant: we use default Flowable schema; column IS_MI_ROOT_ / is_mi_root_ exists on ACT_RU_EXECUTION)

To Reproduce

  1. Deploy a process with a parallel multi-instance user task (e.g. 2 instances, assignee list from a variable).
  2. Start the process so that the MI activity creates 2 child executions and 2 tasks.
  3. Complete one of the user tasks (e.g. via taskService.complete(taskId) or REST).
  4. The NPE occurs during that complete() call when the engine runs ParallelMultiInstanceBehavior.leave() and then setLoopVariable(execution, ...) with a null execution.

Expected behavior

The first completed instance should leave the activity without error; the multi-instance root execution should be found and used for setLoopVariable, and the second instance should remain active.

Actual behavior

getMultiInstanceRootExecution(execution) (or equivalent) appears to return null, so the execution passed to setLoopVariable is null and an NPE is thrown.

Additional context

  • We have two child executions under the MI scope execution; only one task is completed when the error happens.
  • The MI scope execution in the DB has multi-instance variables (nrOfInstances, nrOfCompletedInstances, nrOfActiveInstances). We did not modify Flowable engine code; we only call taskService.complete(taskId) (and before that we update task assignee/category and set process variables on the root execution).
  • We tried (without resolving the issue):
    • Overriding Execution.xml to map the is_mi_root_ column (PostgreSQL lowercase) so that isMultiInstanceRoot() is set correctly when loading executions.
    • Moving updateBusinessStatus() and setVariables() to after complete() so that no extra writes touch executions/variables before the engine’s leave logic runs.
  • We are happy to provide a minimal BPMN or database snapshot if needed for reproduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions