flowable/flowable-engine · error · FlowableIllegalArgumentException
Could not find case element with id
Error message
Could not find case element with id
What it means
Thrown when the case model was found but its allCaseElements map has no entry for the builder's elementId. The elementId passed to the PlanItemInstanceBuilder must match a case element (plan item / stage / milestone id) declared in the case definition; an unknown id cannot be instantiated.
Solutions
- Read the element id from the case model at runtime: cmmnRepositoryService.getCmmnModel(caseDefinitionId) and inspect its plan items instead of hardcoding.
- Confirm the elementId exists in the same case definition version you pass as caseDefinitionId.
- Fix the CMMN XML so the dynamic plan item references an existing planItem id in the stage.
Example fix
// before
planItemInstanceBuilder.elementId("dynamicTask"); // may not exist in deployed model
// after
Case caseModel = cmmnRepositoryService.getCmmnModel(caseDefinitionId).getCases().get(0);
if (!caseModel.getAllCaseElements().containsKey("dynamicTask")) {
throw new IllegalStateException("element dynamicTask missing from case definition");
}
planItemInstanceBuilder.elementId("dynamicTask"); Defensive patterns
Strategy: validation
Validate before calling
Case caseModel = cmmnRepositoryService.getCmmnModel(caseDefinitionId).getCases().get(0);
if (!caseModel.getAllCaseElements().containsKey(elementId)) {
throw new IllegalArgumentException("elementId " + elementId + " not in case definition " + caseDefinitionId);
}
planItemInstanceBuilder.elementId(elementId); Prevention
- Derive element ids from the deployed CmmnModel rather than hardcoding XML ids.
- Re-validate element ids whenever the case definition version changes.
When it happens
Trigger: Calling planItemInstanceBuilder.elementId(id) with an id that does not exist in the referenced case definition: typo, id from a different case model version, or using a task id / plan item instance id instead of the model element id.
Common situations: Hardcoding element ids that changed when the CMMN XML was edited; looking up ids from a newer/older version of the case definition; confusing runtime plan item instance ids with static model element ids.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not find case model with case definition id
- The case element needs to be a plan item, but is a
- A dynamically created plan item can only be injected into a…
- A dynamically created plan item can only be injected into a…
- A 'maxInstanceCount' on a repetition rule with value '0' is…
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/c91a741e81c930e4.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CreateInjectedPlanItemInstanceCmd.java:54
public class CreateInjectedPlanItemInstanceCmd implements Command<PlanItemInstance> {
protected final InjectedPlanItemInstanceBuilderImpl planItemInstanceBuilder;
public CreateInjectedPlanItemInstanceCmd(InjectedPlanItemInstanceBuilderImpl planItemInstanceBuilder) {
this.planItemInstanceBuilder = planItemInstanceBuilder;
}
@Override
public PlanItemInstance execute(CommandContext commandContext) {
Case caseModel = CaseDefinitionUtil.getCase(planItemInstanceBuilder.getCaseDefinitionId());
if (caseModel == null) {
throw new FlowableIllegalArgumentException("Could not find case model with case definition id " + planItemInstanceBuilder.getCaseDefinitionId());
}
CaseElement caseElement = caseModel.getAllCaseElements().get(planItemInstanceBuilder.getElementId());
if (caseElement == null) {
throw new FlowableIllegalArgumentException("Could not find case element with id " + planItemInstanceBuilder.getElementId());
}
if (!(caseElement instanceof PlanItem)) {
throw new FlowableIllegalArgumentException("The case element needs to be a plan item, but is a " + caseElement.getClass().getName());
}
String runningCaseDefinitionId;
String caseInstanceId;
String tenantId;
PlanItemInstance stagePlanItemInstance = null;
if (planItemInstanceBuilder.injectInStage()) {
stagePlanItemInstance = getStageInstanceEntity(commandContext);
caseInstanceId = stagePlanItemInstance.getCaseInstanceId();
tenantId = stagePlanItemInstance.getTenantId();
runningCaseDefinitionId = stagePlanItemInstance.getCaseDefinitionId();
} else if (planItemInstanceBuilder.injectInCase()) {
CaseInstance caseInstance = getCaseInstanceEntity(commandContext);
caseInstanceId = caseInstance.getId();View on GitHub (pinned to d6d39ce1c6)