{"record":{"id":"d08bcda338cca4ff","repo":"flowable/flowable-engine","slug":"event-is-null-d08bcd","errorCode":null,"errorMessage":"event is null","messagePattern":"event is null","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DispatchEventCommand.java","lineNumber":38,"sourceCode":"import org.flowable.common.engine.impl.interceptor.EngineConfigurationConstants;\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 ActivitiIllegalArgumentException(\"event is null\");\n        }\n\n        if (commandContext.getEventDispatcher().isEnabled()) {\n            commandContext.getEventDispatcher().dispatchEvent(event, EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);\n        } else {\n            throw new ActivitiException(\"Message dispatcher is disabled, cannot dispatch event\");\n        }\n\n        return null;\n    }\n\n}\n","sourceCodeStart":20,"sourceCodeEnd":51,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DispatchEventCommand.java#L20-L51","documentation":"DispatchEventCommand dispatches a FlowableEvent through the engine's event dispatcher. Before dispatching, it validates that the event supplied to the command is not null; a null event would otherwise cause a NullPointerException deep inside the dispatcher, so an ActivitiIllegalArgumentException is thrown explicitly.","triggerScenarios":"Calling RuntimeService.dispatchEvent(event) (or DispatchEventCmd via the command API) with a null ActivitiEvent, e.g. a variable holding the event was never initialized or a builder/factory returned null.","commonSituations":"Custom event listeners or integration code that builds events conditionally and passes the result straight to dispatchEvent; refactors where an event-creation helper silently started returning null.","solutions":["Ensure the event passed to runtimeService.dispatchEvent() is non-null before calling it","Verify the event factory (e.g. FlowableEventBuilder) call used to create the event actually succeeded","Check that variables holding the event are initialized before the dispatch call","Wrap the dispatch call in a null check or Objects.requireNonNull with a clear message"],"exampleFix":"// before\nruntimeService.dispatchEvent(event);\n// after\nif (event != null) {\n    runtimeService.dispatchEvent(event);\n} else {\n    throw new IllegalArgumentException(\"Cannot dispatch: event is null\");\n}","handlingStrategy":"validation","validationCode":"if (event == null) { throw new IllegalArgumentException(\"event must not be null before dispatch\"); }","typeGuard":"boolean isDispatchable(ActivitiEvent e) { return e != null; }","tryCatchPattern":"try { runtimeService.dispatchEvent(event); } catch (ActivitiIllegalArgumentException e) { LOGGER.error(\"Null event passed to dispatch\", e); }","preventionTips":["Never dispatch events built by conditional helpers without a null check","Use Objects.requireNonNull(event) at the dispatch call site","Unit test event-producing helpers to assert non-null output"],"tags":["null-check","event-dispatch","illegal-argument"],"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"}