{"record":{"id":"6b8ab578abb745e8","repo":"flowable/flowable-engine","slug":"event-is-null","errorCode":null,"errorMessage":"event is null","messagePattern":"event is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DispatchEventCommand.java","lineNumber":40,"sourceCode":"import org.flowable.engine.impl.util.CommandContextUtil;\n\n/**\n * Command that dispatches an event.\n * \n * @author Frederik Heremans\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(\"event is null\");\n        }\n\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();\n        if (eventDispatcher != null && eventDispatcher.isEnabled()) {\n            eventDispatcher.dispatchEvent(event, processEngineConfiguration.getEngineCfgKey());\n        } else {\n            throw new FlowableException(\"Message dispatcher is disabled, cannot dispatch \" + event);\n        }\n\n        return null;\n    }\n\n}\n","sourceCodeStart":22,"sourceCodeEnd":55,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DispatchEventCommand.java#L22-L55","documentation":"DispatchEventCommand validates that the FlowableEvent to dispatch is non-null and throws FlowableIllegalArgumentException otherwise. The event is then handed to the engine's FlowableEventDispatcher. It exists so a null event fails fast rather than crashing inside dispatcher internals.","triggerScenarios":"Calling runtimeService.dispatchEvent(null) orFlowableEventDispatcher-enabled command wrappers passing an event variable that was never constructed.","commonSituations":"Custom event builders returning null on error paths (e.g. factory method returning null instead of throwing); process variables holding the event being null; reflection/dynamic dispatch building the event object incorrectly.","solutions":["Construct a valid FlowableEvent (e.g. via FlowableEventBuilder) before dispatching.","Null-check the event at the call site and handle the absent case explicitly.","Fix factory/builder methods to throw instead of returning null.","If the event comes from a process variable, add a guard task or validation before the dispatch step."],"exampleFix":"// before\nruntimeService.dispatchEvent(myEvent); // myEvent is null\n// after\nif (myEvent == null) {\n    throw new IllegalStateException(\"event required\");\n}\nruntimeService.dispatchEvent(myEvent);","handlingStrategy":"validation","validationCode":"if (event != null) runtimeService.dispatchEvent(event);","typeGuard":"if (event instanceof FlowableEvent) { runtimeService.dispatchEvent(event); }","tryCatchPattern":"try { rs.dispatchEvent(event); } catch (FlowableIllegalArgumentException e) { log.warn(\"Null event skipped\", e); }","preventionTips":["Make event builders throw instead of returning null","Guard optional event construction paths","Type-check event objects produced by reflection or deserialization"],"tags":["workflow","events","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-14T05:17:10.506Z"}