{"record":{"id":"97400bec58d5f5e3","repo":"flowable/flowable-engine","slug":"entity-cannot-be-null-97400b","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/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 FlowableEngineEventImpl 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-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEntityExceptionEventImpl.java#L16-L50","documentation":"FlowableEntityExceptionEventImpl is a FlowableEntityEventImpl that additionally carries the Throwable that caused the event (e.g. for ENTITY_CREATED-with-exception style error propagation). It inherits the non-null entity contract: constructing it without an entity throws FlowableIllegalArgumentException, even though the cause itself may legitimately be null per this constructor.","triggerScenarios":"Calling new FlowableEntityExceptionEventImpl(null, type, cause) directly; event-building code in custom error handling where the entity reference is null when the failure event is created.","commonSituations":"Custom exception/listener plumbing that creates failure events from a null entity (e.g. entity failed to load); test harnesses constructing exception events without an entity; integration code where an earlier lookup returned null.","solutions":["Pass a non-null entity to the constructor; resolve or substitute the entity before creating the event.","If only the exception matters, use a plain FlowableEventImpl/FlowableExceptionEvent event type not bound to an entity.","Guard the construction site with a null check and log-and-skip when the entity is absent."],"exampleFix":"// before\nevents.add(new FlowableEntityExceptionEventImpl(entityRef.get(), type, cause)); // get() may be null\n\n// after\nif (entityRef.get() != null) {\n    events.add(new FlowableEntityExceptionEventImpl(entityRef.get(), type, cause));\n}","handlingStrategy":"validation","validationCode":"if (entity == null) {\n    log.warn(\"Skipping exception event dispatch: no entity available\");\n    return;\n}\nevents.add(new FlowableEntityExceptionEventImpl(entity, type, cause));","typeGuard":"boolean canBuildExceptionEvent(Object entity) { return entity != null; }","tryCatchPattern":"try {\n    events.add(new FlowableEntityExceptionEventImpl(entity, type, cause));\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"Cannot create entity exception event: entity is null\", e);\n    throw e;\n}","preventionTips":["In error-handling paths, capture the entity reference before the failure can null it out.","Fall back to a non-entity exception event when the entity is unavailable.","Assert non-null entity in custom event factories."],"tags":["events","null-check","constructor","exceptions"],"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"}