flowable/flowable-engine · error · FlowableObjectNotFoundException

No case instance found for id ${caseInstanceId}

Error message

No case instance found for id ${caseInstanceId}

What it means

SetVariablesAsyncCmd verifies that the given caseInstanceId references an existing case instance before adding variables asynchronously. When findById returns null, the id does not match a persisted case instance, so it throws FlowableObjectNotFoundException. This prevents writing variables for a non-existent or already-terminated case.

Source

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

        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");
        }
     
        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(caseInstanceId);
        if (caseInstanceEntity == null) {
            throw new FlowableObjectNotFoundException("No case instance found for id " + caseInstanceId, CaseInstanceEntity.class);
        }
        
        for (String variableName : variables.keySet()) {
            addVariable(false, caseInstanceId, null, variableName, variables.get(variableName), caseInstanceEntity.getTenantId(), 
                    cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService());
        }
        
        createSetAsyncVariablesJob(caseInstanceEntity, cmmnEngineConfiguration);
        
        return null;
    }

}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Verify the caseInstanceId via runtimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult() before calling setVariablesAsync.
  2. Fix the source of the id (log and inspect what value is passed); ensure it is the case instance id, not a plan item or task id.
  3. Handle completion: if the case has ended, fetch variables from history (historyService) instead of setting runtime variables.
  4. Wrap the call in try-catch for FlowableObjectNotFoundException and treat it as a business-level 'case no longer active' condition.

Example fix

// before
runtimeService.setVariablesAsync(caseInstanceId, variables);
// after
CaseInstance ci = runtimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
if (ci != null) {
    runtimeService.setVariablesAsync(caseInstanceId, variables);
} else {
    LOGGER.warn("Case instance {} no longer active; skipping variable update", caseInstanceId);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).count() > 0;
if (!exists) throw new IllegalArgumentException("Unknown caseInstanceId: " + caseInstanceId);

Try / catch

try {
    runtimeService.setVariablesAsync(caseInstanceId, vars);
} catch (FlowableObjectNotFoundException e) {
    // case ended or wrong id; fall back to history-based handling
}

Prevention

When it happens

Trigger: Calling CmmnRuntimeService.setVariablesAsync (or the equivalent management API) with a caseInstanceId that does not exist, was mistyped, or whose case instance has already ended and been archived.

Common situations: Using an id from a different process/case engine; storing a stale id after case completion; a race where the case is terminated between lookup and call; passing a plan item or task id instead of the case instance id.

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