{"record":{"id":"c7e9366094ab3b92","repo":"flowable/flowable-engine","slug":"the-event-to-be-dispatched-must-not-be-null","errorCode":null,"errorMessage":"The event to be dispatched must not be null.","messagePattern":"The event to be dispatched must not be null\\.","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DispatchEventCommand.java","lineNumber":40,"sourceCode":"import org.flowable.common.engine.impl.interceptor.CommandContext;\n\n/**\n * This command dispatches an event within the case engine.\n *\n * @author Micha Kiener\n */\npublic class DispatchEventCommand implements Command<Void> {\n\n    protected FlowableEvent event;\n\n    public DispatchEventCommand(FlowableEvent event) {\n        this.event = event;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (event == null) {\n            throw new FlowableIllegalArgumentException(\"The event to be dispatched must not be null.\");\n        }\n\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        FlowableEventDispatcher eventDispatcher = cmmnEngineConfiguration.getEventDispatcher();\n        if (eventDispatcher != null && eventDispatcher.isEnabled()) {\n            eventDispatcher.dispatchEvent(event, cmmnEngineConfiguration.getEngineCfgKey());\n        } else {\n            throw new FlowableException(\"Message dispatcher is disabled, cannot dispatch event.\");\n        }\n\n        return null;\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":54,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DispatchEventCommand.java#L22-L54","documentation":"FlowableIllegalArgumentException thrown by DispatchEventCommand.execute when the FlowableEvent to dispatch is null. The command exists solely to push a platform event through the event dispatcher, so a null event is a programming error caught up front.","triggerScenarios":"Calling cmmnEngineConfiguration.getEventDispatcher() wrappers / dispatchEvent(null) or constructing new DispatchEventCommand(null).","commonSituations":"Event factory returned null (e.g. builder misused); variable holding the event never initialized; passing the result of a lookup that found no matching event object.","solutions":["Ensure the FlowableEvent instance is built (e.g. FlowableCaseInstanceEventBuilder/FlowableEventBuilder) before dispatching","Null-check the event before invoking dispatch","Return early if your own event-producing code produced nothing"],"exampleFix":"// before\nruntimeService.dispatchEvent(event);\n// after\nif (event != null) {\n    runtimeService.dispatchEvent(event);\n}","handlingStrategy":"validation","validationCode":"if (event == null) throw new IllegalArgumentException(\"event required\");","typeGuard":"boolean canDispatch = event instanceof FlowableEvent;","tryCatchPattern":"try { dispatcher.dispatchEvent(event, key); } catch (FlowableIllegalArgumentException e) { log.error(\"null event supplied\", e); }","preventionTips":["Build events via FlowableEventBuilder factories that never return null","Null-check results of event-producing code before dispatch"],"tags":["cmmn","event-dispatch","null-argument","validation"],"backgroundTag":"null-argument","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"}