{"record":{"id":"79b83705b5fbd6b1","repo":"flowable/flowable-engine","slug":"entity-cannot-be-null-79b837","errorCode":null,"errorMessage":"Entity cannot be null.","messagePattern":"Entity cannot be null\\.","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/impl/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 FlowableProcessEventImpl 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/src/main/java/org/flowable/engine/delegate/event/impl/FlowableEntityEventImpl.java#L14-L42","documentation":"FlowableEntityEventImpl represents an engine entity event and requires a non-null entity. The constructor validates the entity argument and throws FlowableIllegalArgumentException immediately if it is null, since an entity event without an entity is meaningless.","triggerScenarios":"Programmatically constructing new FlowableEntityEventImpl(null, type) — e.g. custom event dispatch code or engine-internal event creation with a null entity object.","commonSituations":"Custom FlowableEventListener / event builder code that passes a null entity; refactors where the entity lookup returned null before event creation.","solutions":["Ensure the entity object is fully loaded and non-null before constructing the event","Add a null check upstream and skip event dispatch when the entity is absent","Catch FlowableIllegalArgumentException around custom event construction during development"],"exampleFix":"// before\ndispatcher.dispatchEvent(new FlowableEntityEventImpl(entity, type));\n// after\nif (entity != null) {\n    dispatcher.dispatchEvent(new FlowableEntityEventImpl(entity, type));\n}","handlingStrategy":"validation","validationCode":"if (entity == null) { throw new IllegalArgumentException(\"entity required before dispatching entity event\"); }","typeGuard":"boolean canDispatch = entity != null;","tryCatchPattern":"try { new FlowableEntityEventImpl(entity, type); } catch (FlowableIllegalArgumentException e) { log.warn(\"skipped event: no entity\"); }","preventionTips":["Never construct entity events from possibly-null lookups","Use Objects.requireNonNull with a clear message at event-factory boundaries","Skip event dispatch when the entity could not be resolved","Test event factories with null-entity paths"],"tags":["flowable","events","null-check"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}