{"record":{"id":"135c6dd547533a4f","repo":"flowable/flowable-engine","slug":"could-not-execute-inner-activity-behavior-of-multi-135c6d","errorCode":null,"errorMessage":"Could not execute inner activity behavior of multi instance behavior","messagePattern":"Could not execute inner activity behavior of multi instance behavior","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/SequentialMultiInstanceBehavior.java","lineNumber":83,"sourceCode":"\n        if (loopCounter != nrOfInstances && !completionConditionSatisfied(execution)) {\n            callActivityEndListeners(execution);\n        }\n\n        setLoopVariable(execution, getCollectionElementIndexVariable(), loopCounter);\n        setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);\n        logLoopDetails(execution, \"instance completed\", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);\n\n        if (loopCounter >= nrOfInstances || completionConditionSatisfied(execution)) {\n            super.leave(execution);\n        } else {\n            try {\n                executeOriginalBehavior(execution, loopCounter);\n            } catch (BpmnError error) {\n                // re-throw business fault so that it can be caught by an Error Intermediate Event or Error Event Sub-Process in the process\n                throw error;\n            } catch (Exception e) {\n                throw new ActivitiException(\"Could not execute inner activity behavior of multi instance behavior\", e);\n            }\n        }\n    }\n\n    @Override\n    public void execute(DelegateExecution execution) {\n        super.execute(execution);\n\n        if (innerActivityBehavior instanceof SubProcessActivityBehavior) {\n            // ACT-1185: end-event in subprocess may have inactivated execution\n            if (!execution.isActive() && execution.isEnded() && (execution.getExecutions() == null || execution.getExecutions().isEmpty())) {\n                execution.setActive(true);\n            }\n        }\n    }\n\n}\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/SequentialMultiInstanceBehavior.java#L65-L101","documentation":"Wraps any exception thrown by the inner activity behavior of a sequential multi-instance activity during executeOriginalBehavior, except BpmnError which is re-thrown for error-event handling. It indicates the delegate/service inside one loop iteration failed, hiding the root cause as the cause of this ActivitiException.","triggerScenarios":"Any exception thrown while executing the wrapped behavior of a loop iteration — e.g. a JavaDelegate throwing RuntimeException, a service task failing to resolve its expression, an NPE in a listener — inside SequentialMultiInstanceBehavior.leave.","commonSituations":"A delegate class throws due to bad input data in one iteration; a service-task expression references a missing variable or bean; an HTTP/DB call inside a delegate fails mid-loop; developers miss the nested 'Caused by' when reading logs.","solutions":["Inspect the full stack trace's 'Caused by' chain — the real failure is the wrapped cause, not this message","Fix the root-cause exception in the inner delegate/behavior for the failing iteration","If the inner failure is a business error, throw a BpmnError from the delegate so it propagates to an error boundary/sub-process instead of being wrapped","Add error boundary events or a try/catch inside the delegate to control loop-failure semantics"],"exampleFix":"// before (delegate throws raw exception)\npublic void execute(DelegateExecution exec) {\n    throw new RuntimeException(\"bad data: \" + exec.getVariable(\"payload\"));\n}\n// after\npublic void execute(DelegateExecution exec) {\n    String payload = (String) exec.getVariable(\"payload\");\n    if (payload == null) {\n        throw new BpmnError(\"INVALID_PAYLOAD\", \"payload missing for iteration\");\n    }\n}","handlingStrategy":"validation","validationCode":"// Ensure inner delegates validate inputs before execution\nif (execution.getVariable(\"loopCounter\") == null) {\n    throw new BpmnError(\"MISSING_LOOP_COUNTER\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.startProcessInstanceByKey(\"process\");\n} catch (ActivitiException e) {\n    log.error(\"Multi-instance inner behavior failed: \", e.getCause());\n}","preventionTips":["Wrap delegates so they throw BpmnError for business failures instead of generic exceptions","Inspect the cause chain of this ActivitiException, not just its message","Test delegates with edge-case data (nulls, empty collections) for each loop iteration","Add an error boundary event on the multi-instance activity for controlled failure handling"],"tags":["bpmn","multi-instance","wrapped-exception","delegate"],"backgroundTag":"internal-invariant-violation","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}