{"record":{"id":"cbd02cf33297ecba","repo":"flowable/flowable-engine","slug":"listener-is-null-cbd02c","errorCode":null,"errorMessage":"listener is null.","messagePattern":"listener is null\\.","errorType":"exception","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/RemoveEventListenerCommand.java","lineNumber":37,"sourceCode":"\n/**\n * Command that removes an event-listener to the Activiti engine.\n * \n * @author Frederik Heremans\n */\npublic class RemoveEventListenerCommand implements Command<Void> {\n\n    protected FlowableEventListener listener;\n\n    public RemoveEventListenerCommand(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 ActivitiIllegalArgumentException(\"listener is null.\");\n        }\n\n        commandContext.getProcessEngineConfiguration()\n                .getEventDispatcher().removeEventListener(listener);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":19,"sourceCodeEnd":47,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/RemoveEventListenerCommand.java#L19-L47","documentation":"RemoveEventListenerCommand.validate/addEventListener dispatch removes an event listener from the engine's event dispatcher, but requires the listener reference to be non-null; a null argument raises ActivitiIllegalArgumentException. Because listeners are removed by object identity, a null (or non-registered) reference is meaningless here.","triggerScenarios":"Calling runtimeService.removeEventListener(null) — typically because the listener variable was never assigned, a @Autowired field was null in a non-Spring-managed class, or the listener instance was reconstructed instead of keeping the originally registered object.","commonSituations":"Spring wiring misconfiguration so the listener field is null; deserialization/config reload recreating a new listener object instead of the registered instance; null default in plugin initialization code.","solutions":["Pass the same listener instance that was passed to addEventListener; keep a strong reference to it for the removal call.","Fix dependency injection so the listener bean is populated (component scan, @Autowired, constructor injection).","Null-check before calling removeEventListener and skip/log if the listener was never registered."],"exampleFix":"// before\nruntimeService.removeEventListener(listener);\n\n// after\nif (listener != null) {\n    runtimeService.removeEventListener(listener);\n}","handlingStrategy":"type-guard","validationCode":"if (listener == null) { log.warn(\"no listener to remove\"); return; }","typeGuard":"boolean canRemove(ActivitiEventListener l) { return l != null; }","tryCatchPattern":"try {\n    runtimeService.removeEventListener(listener);\n} catch (ActivitiIllegalArgumentException e) {\n    log.warn(\"Listener was null, skipping removal\");\n}","preventionTips":["Keep a strong reference to the exact instance passed to addEventListener","Ensure listener beans are injected (not null) before use","Avoid recreating listener objects when the registered one is required for removal"],"tags":["activiti","flowable","null-argument","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"}