flowable/flowable-engine · error · FlowableObjectNotFoundException

case instance ${caseInstanceId} doesn't exist

Error message

case instance ${caseInstanceId} doesn't exist

What it means

HasCaseInstanceVariableCmd.execute throws FlowableObjectNotFoundException when no case instance with the given id exists in the CMMN runtime tables. The id was syntactically valid (non-null) but findById returned no row, so the engine cannot evaluate variable existence for a nonexistent entity.

Source

Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/HasCaseInstanceVariableCmd.java:53

    public HasCaseInstanceVariableCmd(String caseInstanceId, String variableName, boolean isLocal) {
        this.caseInstanceId = caseInstanceId;
        this.variableName = variableName;
        this.isLocal = isLocal;
    }

    @Override
    public Boolean execute(CommandContext commandContext) {
        if (caseInstanceId == null) {
            throw new FlowableIllegalArgumentException("caseInstanceId is null");
        }
        if (variableName == null) {
            throw new FlowableIllegalArgumentException("variableName is null");
        }

        CaseInstanceEntity caseInstance = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceId);

        if (caseInstance == null) {
            throw new FlowableObjectNotFoundException("case instance " + caseInstanceId + " doesn't exist", CaseInstance.class);
        }

        boolean hasVariable = false;

        if (isLocal) {
            hasVariable = caseInstance.hasVariableLocal(variableName);
        } else {
            hasVariable = caseInstance.hasVariable(variableName);
        }

        return hasVariable;
    }
}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Confirm the case instance exists via cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult()
  2. If the case may have completed, use the history service (cmmnHistoryService) instead of runtime
  3. Verify the id origin and that you are connected to the correct database/schema

Example fix

// before
boolean has = cmmnRuntimeService.hasVariable(caseId, "approved");
// after
CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseId).singleResult();
boolean has = ci != null && cmmnRuntimeService.hasVariable(caseId, "approved");
Defensive patterns

Strategy: try-catch

Validate before calling

CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery()
    .caseInstanceId(caseInstanceId).singleResult();
if (ci == null) {
    // fall back to history or treat as not found
}

Type guard

boolean caseInstanceExists(CmmnRuntimeService rs, String id) {
    return id != null && rs.createCaseInstanceQuery().caseInstanceId(id).singleResult() != null;
}

Try / catch

try {
    return cmmnRuntimeService.hasVariable(caseInstanceId, variableName);
} catch (FlowableObjectNotFoundException e) {
    log.warn("Case instance {} not found; checking history", caseInstanceId);
    return cmmnHistoryService.createHistoricVariableInstanceQuery()
        .caseInstanceId(caseInstanceId).variableName(variableName).count() > 0;
}

Prevention

When it happens

Trigger: Calling hasVariable/hasVariableLocal with an id of a case instance that was ended/deleted, a typo'd or truncated id, or an id from a different engine (process vs case instance).

Common situations: Querying variables after case completion (historical data only), hard-coded ids in tests, mixing BPMN process instance ids with CMMN case instance ids, cluster/database mismatch pointing at the wrong schema.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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