{"record":{"id":"73660b12ca0c4027","repo":"flowable/flowable-engine","slug":"the-listener-to-be-registered-must-not-be-null","errorCode":null,"errorMessage":"The listener to be registered must not be null.","messagePattern":"The listener to be registered must not be null\\.","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddEventListenerCommand.java","lineNumber":45,"sourceCode":"public class AddEventListenerCommand  implements Command<Void> {\n\n    protected FlowableEventListener listener;\n    protected FlowableEngineEventType[] types;\n\n    public AddEventListenerCommand(FlowableEventListener listener, FlowableEngineEventType[] types) {\n        this.listener = listener;\n        this.types = types;\n    }\n\n    public AddEventListenerCommand(FlowableEventListener listener) {\n        super();\n        this.listener = listener;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (listener == null) {\n            throw new FlowableIllegalArgumentException(\"The listener to be registered must not be null.\");\n        }\n\n        if (types != null) {\n            CommandContextUtil.getCmmnEngineConfiguration(commandContext).getEventDispatcher().addEventListener(listener, types);\n        } else {\n            CommandContextUtil.getCmmnEngineConfiguration(commandContext).getEventDispatcher().addEventListener(listener);\n        }\n\n        return null;\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":57,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddEventListenerCommand.java#L27-L57","documentation":"AddEventListenerCommand validates that the FlowableEventListener passed to CmmnRuntimeService.addEventListener is non-null before registering it with the engine's event dispatcher. A null listener cannot receive events, so a FlowableIllegalArgumentException is thrown inside the command.","triggerScenarios":"Calling cmmnRuntimeService.addEventListener(null) or cmmnRuntimeService.addEventListener(null, types...) — typically when the listener variable was never initialized, was returned null by a factory/spring lookup, or was accidentally cleared in configuration.","commonSituations":"Spring bean injection failure leaving the listener field null, conditional wiring that skipped listener creation, refactoring that renamed the listener bean, or passing the result of map.get(\"listener\") which is null.","solutions":["Ensure a non-null FlowableEventListener instance is constructed or injected before calling addEventListener","Check DI wiring (Spring bean exists, @Autowired/@Inject satisfied, bean name correct)","Guard the call site: if (listener != null) before registering","Log at startup which listeners were registered to catch silent null wiring early"],"exampleFix":"// before\ncmmnRuntimeService.addEventListener(myListener, arraysOfTypes);\n// after\nObjects.requireNonNull(myListener, \"event listener must be configured\");\ncmmnRuntimeService.addEventListener(myListener, arrayOfTypes);","handlingStrategy":"validation","validationCode":"if (listener == null) throw new IllegalArgumentException(\"listener must be configured before registration\");\ncmmnRuntimeService.addEventListener(listener, types);","typeGuard":"boolean canRegister(FlowableEventListener l) { return l != null; }","tryCatchPattern":"try {\n    cmmnRuntimeService.addEventListener(listener);\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"Listener registration failed: configure the listener bean\", e);\n}","preventionTips":["Use Objects.requireNonNull at bean construction time","Verify Spring DI: listener bean defined and injected, no null from factory lookups","Log registered listeners at startup","Avoid passing results of map.get/optional-unwraps that may be null"],"tags":["cmmn","null-check","event-listener"],"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"}