{"record":{"id":"bc4f9a7d263b0092","repo":"flowable/flowable-engine","slug":"entity-cannot-be-null-bc4f9a","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/FlowableEntityExceptionEventImpl.java","lineNumber":34,"sourceCode":"import 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;\nimport org.flowable.common.engine.api.delegate.event.FlowableExceptionEvent;\n\n/**\n * Base class for all {@link FlowableEvent} implementations, represents an exception occurred, related to an entity.\n *\n * @author Frederik Heremans\n */\npublic class FlowableEntityExceptionEventImpl extends FlowableProcessEventImpl implements FlowableEngineEntityEvent, FlowableExceptionEvent {\n\n    protected Object entity;\n    protected Throwable cause;\n\n    public FlowableEntityExceptionEventImpl(Object entity, FlowableEngineEventType type, Throwable cause) {\n        super(type);\n        if (entity == null) {\n            throw new FlowableIllegalArgumentException(\"Entity cannot be null.\");\n        }\n        this.entity = entity;\n        this.cause = cause;\n    }\n\n    @Override\n    public Object getEntity() {\n        return entity;\n    }\n\n    @Override\n    public Throwable getCause() {\n        return cause;\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":50,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/impl/FlowableEntityExceptionEventImpl.java#L16-L50","documentation":"FlowableEntityExceptionEventImpl wraps an entity event carrying a Throwable cause (e.g. entity FAILED events). Its constructor validates the entity and throws FlowableIllegalArgumentException if the entity is null; only the cause may be null.","triggerScenarios":"Constructing new FlowableEntityEventExceptionImpl(null, type, cause) — usually in custom event creation for failed-entity events with a null entity reference.","commonSituations":"Custom event-listener bridges that build failure events after a failed entity lookup; engine integrations emitting error events with lost entity references.","solutions":["Resolve the actual entity before constructing the exception event","If the entity is unavailable, use a different event type that does not require an entity","Add an upstream null guard before dispatching the event"],"exampleFix":"// before\nnew FlowableEntityExceptionEventImpl(entity, FlowableEngineEventType.ENTITY_DELETED, cause);\n// after\nObjects.requireNonNull(entity, \"entity required for exception event\");\nnew FlowableEntityExceptionEventImpl(entity, FlowableEngineEventType.ENTITY_DELETED, cause);","handlingStrategy":"validation","validationCode":"if (entity == null) { throw new IllegalArgumentException(\"entity required before dispatching entity exception event\"); }","typeGuard":"boolean canDispatch = entity != null;","tryCatchPattern":"try { new FlowableEntityExceptionEventImpl(entity, type, cause); } catch (FlowableIllegalArgumentException e) { log.warn(\"skipped failure event: no entity\"); }","preventionTips":["Resolve the entity reference before emitting failure events","Keep a reference to the original entity throughout error handling paths","Distinguish null-entity cases with a different event type","Unit-test failure event builders with missing entities"],"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"}