{"record":{"id":"837da48e885223e4","repo":"flowable/flowable-engine","slug":"entity-cannot-be-null","errorCode":null,"errorMessage":"Entity cannot be null.","messagePattern":"Entity cannot be null\\.","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEntityEventImpl.java","lineNumber":32,"sourceCode":"\nimport org.flowable.common.engine.api.FlowableIllegalArgumentException;\nimport org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;\nimport org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;\nimport org.flowable.common.engine.api.delegate.event.FlowableEvent;\n\n/**\n * Base class for all {@link FlowableEvent} implementations, related to entities.\n * \n * @author Frederik Heremans\n */\npublic class FlowableEntityEventImpl extends FlowableEngineEventImpl implements FlowableEngineEntityEvent {\n\n    protected Object entity;\n\n    public FlowableEntityEventImpl(Object entity, FlowableEngineEventType type) {\n        super(type);\n        if (entity == null) {\n            throw new FlowableIllegalArgumentException(\"Entity cannot be null.\");\n        }\n        this.entity = entity;\n    }\n\n    @Override\n    public Object getEntity() {\n        return entity;\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":42,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEntityEventImpl.java#L14-L42","documentation":"FlowableEntityEventImpl represents an engine event tied to a specific entity (task, execution, job, etc.). The constructor validates that an entity is provided; constructing the event with a null entity is a programming error because the event would carry no payload, so FlowableIllegalArgumentException is thrown immediately.","triggerScenarios":"Calling new FlowableEntityEventImpl(null, type) directly; dispatching engine event-building code with a null entity reference (e.g. an entity variable that was null when the event was created).","commonSituations":"Custom event listeners/dispatchers building engine events from data that may be null; test code constructing events without an entity; engine-integration code paths where an entity lookup returned null and the result is passed to the constructor unguarded.","solutions":["Pass a non-null entity when constructing the event; resolve the entity before dispatching.","If the entity may be absent, skip dispatching or use a non-entity FlowableEventImpl event instead.","Guard the call site: if (entity != null) { dispatchEvent(new FlowableEntityEventImpl(entity, type)); }"],"exampleFix":"// before\ndispatcher.dispatchEvent(new FlowableEntityEventImpl(maybeNullEntity, FlowableEngineEventType.ENTITY_CREATED));\n\n// after\nif (maybeNullEntity != null) {\n    dispatcher.dispatchEvent(new FlowableEntityEventImpl(maybeNullEntity, FlowableEngineEventType.ENTITY_CREATED));\n}","handlingStrategy":"validation","validationCode":"if (entity == null) {\n    throw new IllegalStateException(\"Refusing to dispatch entity event with null entity\");\n}\ndispatcher.dispatchEvent(new FlowableEntityEventImpl(entity, type));","typeGuard":"boolean canBuildEntityEvent(Object entity) { return entity != null; }","tryCatchPattern":"try {\n    events.add(new FlowableEntityEventImpl(entity, type));\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"Entity event created without entity\", e);\n    throw e;\n}","preventionTips":["Resolve entities before building events; never pass results of unguarded Optional.get() or map lookups.","Use FlowableEventImpl (non-entity event) when no entity is involved.","Add null-assertions in custom event factory methods."],"tags":["events","null-check","constructor"],"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"}