flowable/flowable-engine · error · FlowableIllegalArgumentException

Entity cannot be null.

Error message

Entity cannot be null.

What it means

FlowableEntityEventImpl represents an engine event tied to a specific entity (task, execution, job, etc.). The constructor validates that an entity is provided; constructing the event with a null entity is a programming error because the event would carry no payload, so FlowableIllegalArgumentException is thrown immediately.

Solutions

  1. Pass a non-null entity when constructing the event; resolve the entity before dispatching.
  2. If the entity may be absent, skip dispatching or use a non-entity FlowableEventImpl event instead.
  3. Guard the call site: if (entity != null) { dispatchEvent(new FlowableEntityEventImpl(entity, type)); }

Example fix

// before
dispatcher.dispatchEvent(new FlowableEntityEventImpl(maybeNullEntity, FlowableEngineEventType.ENTITY_CREATED));

// after
if (maybeNullEntity != null) {
    dispatcher.dispatchEvent(new FlowableEntityEventImpl(maybeNullEntity, FlowableEngineEventType.ENTITY_CREATED));
}
Defensive patterns

Strategy: validation

Validate before calling

if (entity == null) {
    throw new IllegalStateException("Refusing to dispatch entity event with null entity");
}
dispatcher.dispatchEvent(new FlowableEntityEventImpl(entity, type));

Type guard

boolean canBuildEntityEvent(Object entity) { return entity != null; }

Try / catch

try {
    events.add(new FlowableEntityEventImpl(entity, type));
} catch (FlowableIllegalArgumentException e) {
    log.error("Entity event created without entity", e);
    throw e;
}

Prevention

When it happens

Trigger: Calling new FlowableEntityEventImpl(null, type) directly; dispatching engine event-building code with a null entity reference (e.g. an entity variable that was null when the event was created).

Common situations: Custom event listeners/dispatchers building engine events from data that may be null; test code constructing events without an entity; engine-integration code paths where an entity lookup returned null and the result is passed to the constructor unguarded.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/837da48e885223e4. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEntityEventImpl.java:32

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;

/**
 * Base class for all {@link FlowableEvent} implementations, related to entities.
 * 
 * @author Frederik Heremans
 */
public class FlowableEntityEventImpl extends FlowableEngineEventImpl implements FlowableEngineEntityEvent {

    protected Object entity;

    public FlowableEntityEventImpl(Object entity, FlowableEngineEventType type) {
        super(type);
        if (entity == null) {
            throw new FlowableIllegalArgumentException("Entity cannot be null.");
        }
        this.entity = entity;
    }

    @Override
    public Object getEntity() {
        return entity;
    }
}

View on GitHub (pinned to d6d39ce1c6)