flowable/flowable-engine · error · FlowableObjectNotFoundException

No case instance found for id ${caseInstanceId}

Error message

No case instance found for id ${caseInstanceId}

What it means

SetVariablesCmd looks up the case instance by id with the CaseInstanceEntityManager; when no persisted case instance matches, it throws FlowableObjectNotFoundException. This guards the subsequent setVariables/plan-item operations from acting on a non-existent case.

Source

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

        this.caseInstanceId = caseInstanceId;
        this.variables = variables;
    }
    
    @Override
    public Void execute(CommandContext commandContext) {
        if (caseInstanceId == null) {
            throw new FlowableIllegalArgumentException("caseInstanceId is null");
        }
        if (variables == null) {
            throw new FlowableIllegalArgumentException("variables is null");
        }
        if (variables.isEmpty()) {
            throw new FlowableIllegalArgumentException("variables is empty");
        }
     
        CaseInstanceEntity caseInstanceEntity = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceId);
        if (caseInstanceEntity == null) {
            throw new FlowableObjectNotFoundException("No case instance found for id " + caseInstanceId, CaseInstanceEntity.class);
        }
        caseInstanceEntity.setVariables(variables);
        
        Set<String> variableNames = variables.keySet();
        
        CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);
        
        CmmnDeploymentManager deploymentManager = CommandContextUtil.getCmmnEngineConfiguration(commandContext).getDeploymentManager();
        CaseDefinition caseDefinition = deploymentManager.findDeployedCaseDefinitionById(caseInstanceEntity.getCaseDefinitionId());
        boolean evaluateVariableEventListener = false;
        if (caseDefinition != null) {
            CmmnModel cmmnModel = deploymentManager.resolveCaseDefinition(caseDefinition).getCmmnModel();
            for (Case caze : cmmnModel.getCases()) {
                List<VariableEventListener> variableEventListeners = caze.findPlanItemDefinitionsOfType(VariableEventListener.class);
                for (VariableEventListener variableEventListener : variableEventListeners) {
                    if (variableNames.contains(variableEventListener.getVariableName())) {
                        evaluateVariableEventListener = true;
                        break;

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Confirm the id exists at call time: runtimeService.createCaseInstanceQuery().caseInstanceId(id).count() == 1.
  2. Correct the id source; use the CaseInstance entity's getId() rather than a hand-built string.
  3. If the case may legitimately be finished, catch FlowableObjectNotFoundException and route to history-based handling.
  4. Add a retry/idempotency check in async flows where the case can terminate concurrently.

Example fix

// before
runtimeService.setVariables(caseInstanceId, variables);
// after
CaseInstance ci = runtimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
if (ci == null) {
    throw new IllegalStateException("Case instance " + caseInstanceId + " not found or already ended");
}
runtimeService.setVariables(caseInstanceId, variables);
Defensive patterns

Strategy: try-catch

Validate before calling

CaseInstance ci = runtimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
if (ci == null) throw new IllegalStateException("Case instance not found: " + caseInstanceId);

Try / catch

try {
    runtimeService.setVariables(caseInstanceId, vars);
} catch (FlowableObjectNotFoundException e) {
    // check history / mark record as orphaned
    HistoricCaseInstance h = historyService.createHistoricCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
}

Prevention

When it happens

Trigger: Calling CmmnRuntimeService.setVariables with an id that matches no case instance: typo, wrong id type, or the case instance already completed and removed from runtime data.

Common situations: Case finished between fetching the id and calling setVariables; id taken from a historic record; cross-environment copy-paste (test id used in prod).

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/f0ff4a8e3c63ff07. Report an issue: GitHub.