{"record":{"id":"16b03b13d762750b","repo":"flowable/flowable-engine","slug":"entity-cannot-be-null-16b03b","errorCode":null,"errorMessage":"Entity cannot be null.","messagePattern":"Entity cannot be null\\.","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/delegate/event/impl/ActivitiEntityEventImpl.java","lineNumber":32,"sourceCode":"\nimport org.activiti.engine.ActivitiIllegalArgumentException;\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 ActivitiEntityEventImpl extends ActivitiEventImpl implements FlowableEngineEntityEvent {\n\n    protected Object entity;\n\n    public ActivitiEntityEventImpl(Object entity, FlowableEngineEventType type) {\n        super(type);\n        if (entity == null) {\n            throw new ActivitiIllegalArgumentException(\"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/flowable5-engine/src/main/java/org/activiti/engine/delegate/event/impl/ActivitiEntityEventImpl.java#L14-L42","documentation":"ActivitiEntityEventImpl wraps an engine entity (task, execution, process instance, etc.) in an entity-related event. Its constructor validates the entity is non-null and throws ActivitiIllegalArgumentException otherwise, since an ENTITY_* event with no entity carries no information. It is normally thrown by ActivitiEventBuilder, not user code.","triggerScenarios":"new ActivitiEntityEventImpl(null, FlowableEngineEventType.ENTITY_CREATED) or ActivitiEventBuilder.createEntityEvent(type, null) with a null entity.","commonSituations":"Custom event listeners/builders dispatching events from hooks where the looked-up entity was null (e.g. entity deleted before event build); test code constructing events manually.","solutions":["Pass the actual engine entity (Task, ExecutionEntity, ProcessInstance, Job, ...) to the constructor/builder.","In custom dispatch code, check entity != null before calling ActivitiEventBuilder.createEntityEvent.","If the entity is null because the row is gone, skip emitting the event instead of constructing one."],"exampleFix":"// before\neventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(type, null));\n// after\nif (entity != null) {\n    eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(type, entity));\n}","handlingStrategy":"type-guard","validationCode":"if (entity == null) { return; // skip event dispatch }","typeGuard":"boolean canDispatchEntityEvent(Object entity) { return entity != null; }","tryCatchPattern":"try { dispatcher.dispatchEvent(builder.build()); } catch (ActivitiIllegalArgumentException e) { logger.warn(\"Skipped entity event with null entity\"); }","preventionTips":["Always build events through ActivitiEventBuilder factory methods","Re-fetch or verify entity existence before emitting lifecycle events","Guard custom dispatch code with null checks"],"tags":["events","null-argument","constructor","validation"],"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"}