flowable/flowable-engine · error · FlowableIllegalArgumentException
The stage plan item instance id could not be found or is no
Error message
The stage plan item instance id could not be found or is no longer active.
What it means
CreateInjectedPlanItemInstanceCmd looks up the target stage plan item instance by id before injecting a dynamically created plan item into it. When the PlanItemInstanceEntityManager returns null for the given stagePlanItemInstanceId, the command throws this FlowableIllegalArgumentException. It means the id does not exist, points to a different engine/database, or the plan item instance has been terminated/completed and removed from active query scope.
Source
Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CreateInjectedPlanItemInstanceCmd.java:106
.tenantId(tenantId)
.addToParent(true)
.create();
// after adding the plan item to the stage, add it to the agenda for creation and afterwards for activation processing
CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);
agenda.planCreatePlanItemInstanceOperation(planItemInstanceEntity);
agenda.planEvaluateToActivatePlanItemInstanceOperation(planItemInstanceEntity);
return planItemInstanceEntity;
}
protected PlanItemInstanceEntity getStageInstanceEntity(CommandContext commandContext) {
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
- Fetch the current stage id via CmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceStateActive()... before injecting, and pass the fresh id
- Verify the plan item instance still exists and is active (query the runtime tables ACT_CMMN_RU_PLAN_ITEM_INST) before calling the injection builder
- Confirm you are connected to the same CmmnEngineConfiguration/database that owns the case instance
- Check that you are not passing a historic plan item instance id instead of a runtime one
Example fix
// before
planItemInstanceBuilder.stagePlanItemInstanceId(storedStageId).inject();
// after
PlanItemInstance stage = cmmnRuntimeService.createPlanItemInstanceQuery()
.planItemInstanceId(storedStageId)
.planItemInstanceState(PlanItemInstanceState.ACTIVE)
.singleResult();
if (stage != null) {
planItemInstanceBuilder.stagePlanItemInstanceId(stage.getId()).inject();
} Defensive patterns
Strategy: validation
Validate before calling
PlanItemInstance stage = cmmnRuntimeService.createPlanItemInstanceQuery()
.planItemInstanceId(stagePlanItemInstanceId)
.planItemInstanceState(PlanItemInstanceState.ACTIVE)
.singleResult();
if (stage == null) throw new IllegalStateException("stage plan item not active: " + stagePlanItemInstanceId); Try / catch
try { builder.stagePlanItemInstanceId(id).inject(); }
catch (FlowableIllegalArgumentException e) { if (e.getMessage().contains("could not be found or is no longer active")) { /* refresh id and retry once */ } else throw e; } Prevention
- Always resolve stage ids from a fresh runtime query, never long-lived caches
- Filter queries on active state before injecting
- Keep injection calls within the same transaction/scope that verified the stage
When it happens
Trigger: Calling dynamic injection APIs (e.g. CmmnRuntimeService.createPlanItemInstanceBuilder(...).stagePlanItemInstanceId(id).inject() / CreateInjectedPlanItemInstanceBuilder) with a stagePlanItemInstanceId that is null, misspelled, already ended, or belongs to another case engine configuration.
Common situations: Stale ids held across long-running transactions after the stage completed; passing a plan item id from a different engine or cluster; copying an id from history instead of runtime; test data referencing a dropped in-memory H2 database.
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
- The case instance with id could not be found or is no longe
- Cannot find plan item with definition id '<planItemDefinitio
- Plan item instance for {eventSubscription} can not be found
- Could not find plan item instance for plan item with definit
- Can only trigger a plan item that is in the ACTIVE state
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/5cc698c394cdebee.
Report an issue: GitHub.