{"record":{"id":"806ed3176bb90557","repo":"flowable/flowable-engine","slug":"event-consumer-is-null-806ed3","errorCode":null,"errorMessage":"event consumer is null.","messagePattern":"event consumer is null\\.","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/RemoveEventConsumerCommand.java","lineNumber":32,"sourceCode":"\nimport org.flowable.common.engine.api.FlowableIllegalArgumentException;\nimport org.flowable.common.engine.impl.interceptor.Command;\nimport org.flowable.common.engine.impl.interceptor.CommandContext;\nimport org.flowable.engine.impl.util.CommandContextUtil;\nimport org.flowable.eventregistry.api.EventRegistryEventConsumer;\n\npublic class RemoveEventConsumerCommand implements Command<Void> {\n\n    protected EventRegistryEventConsumer eventConsumer;\n\n    public RemoveEventConsumerCommand(EventRegistryEventConsumer eventConsumer) {\n        this.eventConsumer = eventConsumer;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (eventConsumer == null) {\n            throw new FlowableIllegalArgumentException(\"event consumer is null.\");\n        }\n\n        CommandContextUtil.getEventRegistry().removeFlowableEventRegistryEventConsumer(eventConsumer);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":14,"sourceCodeEnd":41,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/RemoveEventConsumerCommand.java#L14-L41","documentation":"RemoveEventConsumerCommand removes a FlowableEventRegistryEventConsumer from the event registry via the engine command stack. The command validates its constructor argument and throws FlowableIllegalArgumentException if the event consumer is null. This is a programmer-error guard: a null consumer can never be removed meaningfully.","triggerScenarios":"Calling runtimeService.removeEventConsumer(null) (or constructing RemoveEventConsumerCommand with a null FlowableEventRegistryEventConsumer), typically when the variable holding the consumer was never initialized or was already resolved to null.","commonSituations":"Storing event consumers in a map/collection and passing a lookup result that returned null; a refactored code path that stopped creating the consumer before removal; cleanup code in a shutdown hook where the consumer registration failed earlier and the reference stayed null.","solutions":["Ensure the FlowableEventRegistryEventConsumer instance is non-null before calling removeEventConsumer; keep the reference returned when the consumer was created/registered.","Add a null check or Objects.requireNonNull around the consumer in calling code and skip removal when it was never created.","Fix the code path that fails to initialize the consumer (e.g. registration exception swallowed earlier) so removal operates on a real object."],"exampleFix":"// before\nruntimeService.removeEventConsumer(consumer); // consumer may be null\n// after\nif (consumer != null) {\n    runtimeService.removeEventConsumer(consumer);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean isRemovable(FlowableEventRegistryEventConsumer consumer) {\n    return consumer != null;\n}","tryCatchPattern":"try {\n    runtimeService.removeEventConsumer(consumer);\n} catch (FlowableIllegalArgumentException e) {\n    // consumer was null; nothing to remove\n}","preventionTips":["Keep the reference returned when creating/registering an event consumer and reuse it for removal.","Use Objects.requireNonNull on consumers at creation time so nulls never propagate.","In teardown code, skip removal when the registration never succeeded."],"tags":["flowable","event-registry","null-argument","event-consumer"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}