{"record":{"id":"52b8d871e1e7ba8a","repo":"flowable/flowable-engine","slug":"execution-execution-is-not-a-processinstance","errorCode":null,"errorMessage":"Execution '<execution>' is not a processInstance","messagePattern":"Execution '<execution>' is not a processInstance","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/impl/FlowableProcessTerminatedEventImpl.java","lineNumber":33,"sourceCode":"import org.flowable.common.engine.api.FlowableException;\nimport org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;\nimport org.flowable.common.engine.api.scope.ScopeTypes;\nimport org.flowable.engine.delegate.event.FlowableProcessTerminatedEvent;\nimport org.flowable.engine.impl.persistence.entity.ExecutionEntity;\n\n/**\n * An {@link FlowableProcessTerminatedEvent} implementation.\n *\n * @author martin.grofcik\n */\npublic class FlowableProcessTerminatedEventImpl extends FlowableEntityEventImpl implements FlowableProcessTerminatedEvent {\n\n    protected Object cause;\n\n    public FlowableProcessTerminatedEventImpl(ExecutionEntity execution, Object cause) {\n        super(execution, FlowableEngineEventType.PROCESS_COMPLETED_WITH_TERMINATE_END_EVENT);\n        if (!execution.isProcessInstanceType()) {\n            throw new FlowableException(\"Execution '\"+ execution +\"' is not a processInstance\");\n        }\n        \n        this.subScopeId = execution.getId();\n        this.scopeId = execution.getProcessInstanceId();\n        this.scopeDefinitionId = execution.getProcessDefinitionId();\n        this.scopeType = ScopeTypes.BPMN;\n        this.cause = cause;\n    }\n\n    @Override\n    public Object getCause() {\n        return cause;\n    }\n\n}\n","sourceCodeStart":15,"sourceCodeEnd":49,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/impl/FlowableProcessTerminatedEventImpl.java#L15-L49","documentation":"FlowableProcessTerminatedEventImpl models completion of a process instance via a terminate end event. Its constructor requires the passed execution to be of process-instance type; if not, it throws FlowableException because terminate events are scoped to the process instance execution only.","triggerScenarios":"Constructing this event with an ExecutionEntity whose isProcessInstanceType() is false — e.g. a child/concurrent scope execution (embedded sub-process branch or call-activity child) rather than the root process instance execution.","commonSituations":"Custom event dispatching during process termination that picks the wrong execution from the execution tree; integrations logging terminate-end-event behavior using a nested execution reference.","solutions":["Pass the process instance execution (execution.getProcessInstanceId() / root execution) instead of a child scope execution","Check execution.isProcessInstanceType() before constructing the event","When handling termination in a listener, resolve ExecutionEntityManager to fetch the process instance execution"],"exampleFix":"// before\nnew FlowableProcessTerminatedEventImpl(execution, cause);\n// after\nExecutionEntity pi = execution.isProcessInstanceType()\n    ? execution\n    : execution.getProcessInstance();\nnew FlowableProcessTerminatedEventImpl(pi, cause);","handlingStrategy":"validation","validationCode":"if (!execution.isProcessInstanceType()) { throw new IllegalArgumentException(\"terminate event requires process instance execution\"); }","typeGuard":"boolean isProcessInstance = execution.isProcessInstanceType();","tryCatchPattern":"try { new FlowableProcessTerminatedEventImpl(execution, cause); } catch (FlowableException e) { /* resolve process instance and retry */ }","preventionTips":["Always pass execution.getProcessInstance() (root execution) to process-level events","Check isProcessInstanceType() before process-scoped APIs","When walking the execution tree, resolve to the process instance early","Avoid caching child executions for later process-level event emission"],"tags":["flowable","events","execution-tree"],"backgroundTag":"invalid-state-transition","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}