{"record":{"id":"b3fbcd12a44456b3","repo":"flowable/flowable-engine","slug":"entity-cannot-be-null-b3fbcd","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/ActivitiEntityExceptionEventImpl.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 ActivitiEntityExceptionEventImpl extends ActivitiEventImpl implements FlowableEngineEntityEvent, FlowableExceptionEvent {\n\n    protected Object entity;\n    protected Throwable cause;\n\n    public ActivitiEntityExceptionEventImpl(Object entity, FlowableEngineEventType type, Throwable cause) {\n        super(type);\n        if (entity == null) {\n            throw new ActivitiIllegalArgumentException(\"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/flowable5-engine/src/main/java/org/activiti/engine/delegate/event/impl/ActivitiEntityExceptionEventImpl.java#L16-L50","documentation":"ActivitiEntityExceptionEventImpl is the entity event variant that also carries a Throwable cause (e.g. ENTITY_JOB_FAILED). Its constructor validates the entity is non-null, throwing ActivitiIllegalArgumentException otherwise — an exception event without its subject entity is meaningless.","triggerScenarios":"new ActivitiEntityExceptionEventImpl(null, FlowableEngineEventType.ENTITY_JOB_FAILED, cause) or ActivitiEventBuilder.createEntityExceptionEvent(type, null, cause).","commonSituations":"Custom failure-reporting code building job/execution exception events where the entity lookup failed; hand-constructed events in tests or instrumentation around async job failure handling.","solutions":["Pass the failing entity (typically the Job/Execution) into the builder.","Guard with a null check before constructing/dispatching.","If only the cause is available without an entity, use a plain ActivitiExceptionEvent instead of the entity variant."],"exampleFix":"// before\ndispatch(new ActivitiEntityExceptionEventImpl(null, ENTITY_JOB_FAILED, t));\n// after\nif (job != null) {\n    dispatch(new ActivitiEntityExceptionEventImpl(job, ENTITY_JOB_FAILED, t));\n}","handlingStrategy":"type-guard","validationCode":"if (entity == null || cause == null) { return; }","typeGuard":"boolean canDispatchExceptionEvent(Object entity, Throwable cause) { return entity != null; }","tryCatchPattern":"try { dispatchFailureEvent(entity, cause); } catch (ActivitiIllegalArgumentException e) { logger.warn(\"Cannot dispatch exception event: no entity\", e); }","preventionTips":["Only construct entity exception events inside hooks that already hold the entity","Use ActivitiEventBuilder.createEntityExceptionEvent with the actual Job/Execution","Log-and-skip when the entity has been removed concurrently"],"tags":["events","null-argument","constructor","jobs"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}