{"record":{"id":"9fce442a5c426b10","repo":"flowable/flowable-engine","slug":"no-execution-context-active-and-event-is-not-relat","errorCode":null,"errorMessage":"No execution context active and event is not related to an execution. No compensation event can be thrown.","messagePattern":"No execution context active and event is not related to an execution\\. No compensation event can be thrown\\.","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ErrorThrowingEventListener.java","lineNumber":46,"sourceCode":"public class ErrorThrowingEventListener extends BaseDelegateEventListener {\n\n    protected String errorCode;\n\n    @Override\n    public void onEvent(FlowableEvent event) {\n        if (isValidEvent(event) && event instanceof FlowableEngineEvent) {\n            FlowableEngineEvent engineEvent = (FlowableEngineEvent) event;\n            ExecutionEntity execution = null;\n\n            if (Context.isExecutionContextActive()) {\n                execution = Context.getExecutionContext().getExecution();\n            } else if (engineEvent.getExecutionId() != null) {\n                // Get the execution based on the event's execution ID instead\n                execution = Context.getCommandContext().getExecutionEntityManager().findExecutionById(engineEvent.getExecutionId());\n            }\n\n            if (execution == null) {\n                throw new ActivitiException(\"No execution context active and event is not related to an execution. No compensation event can be thrown.\");\n            }\n\n            try {\n                ErrorPropagation.propagateError(errorCode, execution);\n            } catch (Exception e) {\n                throw new ActivitiException(\"Error while propagating error-event\", e);\n            }\n        }\n    }\n\n    public void setErrorCode(String errorCode) {\n        this.errorCode = errorCode;\n    }\n\n    @Override\n    public boolean isFailOnException() {\n        return true;\n    }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ErrorThrowingEventListener.java#L28-L64","documentation":"ErrorThrowingEventListener (for compensation/error events) needs an execution to propagate the error through. If there is no active command context execution and the dispatched event carries no executionId, propagation is impossible and it throws ActivitiException.","triggerScenarios":"A global engine event listener configured to throw an error event fires for an event unrelated to any execution (e.g. engine-level event) or outside an active command context, so neither Context.getExecutionEntityManager lookup nor engineEvent.getExecutionId() yields an execution.","commonSituations":"Registering an error-throwing listener on engine-wide events (e.g. CONFIGURATION_*, job/async events without execution); dispatching events from a non-command thread; listener used on events that occur before/after process execution exists.","solutions":["Attach the error-throwing listener only to execution-scoped event types that carry an executionId","Dispatch the listener within a command context (e.g. from process logic rather than external threads)","Check event types in the listener registration and remove ones unrelated to executions","If the event legitimately has no execution, use a different listener mechanism that doesn't need an execution"],"exampleFix":"// before\n<flowable:eventListener events=\"ENGINE_CREATED\" delegateExpression=\"${errorThrowingListener}\"/>\n// after\n<flowable:eventListener events=\"ACTIVITY_COMPLETED\" delegateExpression=\"${errorThrowingListener}\"/>","handlingStrategy":"validation","validationCode":"// only register error-throwing listeners for execution-bound events\njava.util.Set<String> EXECUTION_EVENTS = java.util.Set.of(\"ACTIVITY_STARTED\",\"ACTIVITY_COMPLETED\",\"ACTIVITY_SIGNALED\",\"PROCESS_STARTED\",\"PROCESS_COMPLETED\");\nif (!EXECUTION_EVENTS.contains(eventType)) throw new IllegalArgumentException(\"error-throwing listener needs execution-bound event, got \" + eventType);","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.startProcessInstanceByKey(\"myProcess\");\n} catch (org.activiti.engine.ActivitiException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"No execution context active\")) {\n        logger.error(\"Error-throwing listener fired without execution context\", e);\n    }\n    throw e;\n}","preventionTips":["Register error-throwing listeners only on execution-related event types","Do not dispatch such listeners from threads without a command context","Review engine-wide (global) listener registrations for execution dependence"],"tags":["java","events","listener","bpmn"],"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-18T11:17:12.947Z"}