flowable/flowable-engine · error · FlowableIllegalArgumentException

Cannot find activity '" + activityId + "' in process definit

Error message

Cannot find activity '" + activityId + "' in process definition with id '" + bpmnModel.getMainProcess().getId() + "'

What it means

resolveFlowElementFromBpmnModel looks up the requested activity id in the BpmnModel of the (source or target) process definition. If bpmnModel.getFlowElement(activityId) returns null, the definition has no such flow element at the top level, so the move target/source is invalid.

Source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java:450

                if (bpmnModelToMigrateTo != null) {
                	newFlowElement = resolveFlowElementFromBpmnModel(bpmnModelToMigrateTo, activityId);
                } else {
                	newFlowElement = resolveFlowElementFromBpmnModel(bpmnModel, activityId);
                }
            }

            moveExecutionContainer.addMoveToFlowElement(activityId, currentFlowElement, newFlowElement);
            moveExecutionContainer.addCurrentActivityToNewElement(currentActivityId, currentFlowElement, newFlowElement);
            canContainerDirectMigrate = canContainerDirectMigrate && isDirectFlowElementExecutionMigration(currentFlowElement, newFlowElement);
        }

        moveExecutionContainer.setDirectExecutionMigration(canContainerDirectMigrate && migrateToProcessDefinition != null);
    }

    protected FlowElement resolveFlowElementFromBpmnModel(BpmnModel bpmnModel, String activityId) {
        FlowElement flowElement = bpmnModel.getFlowElement(activityId);
        if (flowElement == null) {
            throw new FlowableIllegalArgumentException("Cannot find activity '" + activityId + "' in process definition with id '" + bpmnModel.getMainProcess().getId() + "'");
        }
        return flowElement;
    }
    //-- Move container preparation section end

    protected void doMoveExecutionState(ProcessInstanceChangeState processInstanceChangeState, CommandContext commandContext) {
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
        Map<String, List<ExecutionEntity>> activeEmbeddedSubProcesses = resolveActiveEmbeddedSubProcesses(processInstanceChangeState.getProcessInstanceId(), commandContext);
        processInstanceChangeState.setProcessInstanceActiveEmbeddedExecutions(activeEmbeddedSubProcesses);

        //Set the processInstance variables first so they are available during the change state
        ExecutionEntity processInstanceExecution = executionEntityManager.findById(processInstanceChangeState.getProcessInstanceId());
        processInstanceExecution.setVariables(processInstanceChangeState.getProcessInstanceVariables());

        for (MoveExecutionEntityContainer moveExecutionContainer : processInstanceChangeState.getMoveExecutionEntityContainers()) {
            prepareMoveExecutionEntityContainer(moveExecutionContainer, processInstanceChangeState.getProcessDefinitionToMigrateTo(), commandContext);
            // Action the moves (changeState)
            if (moveExecutionContainer.isMoveToParentProcess()) {

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Verify the id exists in the deployed BPMN XML for that exact process definition id/version
  2. Use the repositoryService.getBpmnModel(processDefinitionId) to enumerate valid flow element ids before the call
  3. If the activity is inside a subprocess, use the appropriate scope-aware move operation

Example fix

// before
.moveActivityIdTo("aprooveTask", "nextTask")
// after
BpmnModel model = repositoryService.getBpmnModel(procDefId);
if (model.getFlowElement("approveTask") != null) { builder.moveActivityIdTo("approveTask","nextTask"); }
Defensive patterns

Strategy: validation

Validate before calling

BpmnModel model = repositoryService.getBpmnModel(procDefId);
if (model.getFlowElement(activityId) == null) throw new IllegalArgumentException("Unknown activity " + activityId);

Try / catch

try { builder.changeState(); } catch (FlowableIllegalArgumentException e) { if (e.getMessage().startsWith("Cannot find activity")) { /* fix ids */ } else throw e; }

Prevention

When it happens

Trigger: Passing an activityId to moveActivityIdTo/moveActivityId current flows that does not exist in the referenced process definition's BPMN model (or exists only nested and unresolvable at that level).

Common situations: Typos in activity ids; id exists in a different process definition version than the one being migrated to; activity inside a subprocess requiring a scoped lookup; deploying a changed BPMN that renamed the element.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/579d3eace28f9445. Report an issue: GitHub.