flowable/flowable-engine · error · FlowableIllegalArgumentException

The case instance with id could not be found or is no longe

Error message

The case instance with id  could not be found or is no longer an active case instance.

What it means

When building an injected plan item, the command resolves the owning case instance via CaseInstanceEntityManager.findById(caseInstanceId). If no case instance entity is returned, this FlowableIllegalArgumentException is thrown. The id is absent, wrong, or the case has ended and is no longer in the runtime tables.

Source

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

        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
        PlanItemInstanceEntity planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager()
            .findById(planItemInstanceBuilder.getStagePlanItemInstanceId());

        if (planItemInstanceEntity == null) {
            throw new FlowableIllegalArgumentException(
                "The stage plan item instance id " + planItemInstanceBuilder.getStagePlanItemInstanceId() + " could not be found or is no longer active.");
        }
        if (!planItemInstanceEntity.isStage()) {
            throw new FlowableIllegalArgumentException("A dynamically created plan item can only be injected into a running stage plan item.");
        }
        return planItemInstanceEntity;
    }

    protected CaseInstanceEntity getCaseInstanceEntity(CommandContext commandContext) {
        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(planItemInstanceBuilder.getCaseInstanceId());
        if (caseInstanceEntity == null) {
            throw new FlowableIllegalArgumentException(
                "The case instance with id " + planItemInstanceBuilder.getCaseInstanceId() + " could not be found or is no longer an active case instance.");
        }
        return caseInstanceEntity;
    }
}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Re-query CmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id) to confirm the case is active before injecting
  2. Pass a fresh caseInstanceId obtained from the running case, not a cached or historic one
  3. Verify the id targets the same database/engine configuration the command runs in

Example fix

// before
builder.caseInstanceId(savedCaseId).inject();
// after
CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(savedCaseId).singleResult();
if (ci != null) {
    builder.caseInstanceId(ci.getId()).inject();
}
Defensive patterns

Strategy: validation

Validate before calling

CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
if (ci == null) throw new IllegalStateException("case not active: " + caseInstanceId);

Try / catch

try { builder.caseInstanceId(caseId).inject(); }
catch (FlowableIllegalArgumentException e) { if (e.getMessage().contains("could not be found or is no longer an active case instance")) { /* refresh case id */ } else throw e; }

Prevention

When it happens

Trigger: Calling planItemInstanceBuilder.caseInstanceId(id) with a null, stale, or foreign id, or after the case instance has completed/terminated and moved to history.

Common situations: Keeping the caseInstanceId in an external store and reusing it after case completion; pointing at another engine's database; passing a historic case instance id; typos from manual test scripts.

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