flowable/flowable-engine · error · FlowableException

The current flow element of the requested is not an ad-hoc…

Error message

The current flow element of the requested  is not an ad-hoc sub process

What it means

CompleteAdhocSubProcessCmd requires the execution's current flow element to actually be an AdhocSubProcess. Flowable throws FlowableException when the execution points at a different BPMN element type.

Solutions

  1. Pass the execution id of the execution whose current flow element is the ad-hoc sub-process (e.g. the child execution of the process instance).
  2. Confirm the BPMN model declares <adhocSubProcess>, not a regular subProcess.
  3. Inspect runtimeService.createExecutionQuery().executionId(id).singleResult() and its activityId against the model.

Example fix

// before
runtimeService.completeAdhocSubProcess(innerTaskExecutionId, outcome);
// after
// use the execution at the ad-hoc sub-process level
runtimeService.completeAdhocSubProcess(adhocSubProcessExecutionId, outcome);
Defensive patterns

Strategy: validation

Validate before calling

ExecutionEntity e = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();
// ensure e.getActivityId() maps to the adhocSubProcess element in the BPMN model, not an inner activity

Try / catch

try {
    runtimeService.completeAdhocSubProcess(executionId, outcome);
} catch (FlowableException e) {
    if (e.getMessage().contains("not an ad-hoc sub process")) {
        // wrong execution id passed; locate the sub-process execution
    }
}

Prevention

When it happens

Trigger: Calling completeAdhocSubProcess(executionId, ...) on an execution whose currentFlowElement is a user task, subprocess, or other element instead of an ad-hoc sub-process.

Common situations: Confusing execution ids of activities inside the ad-hoc sub-process with the execution hosting the sub-process itself; using the API on a regular embedded sub-process.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

    private static final long serialVersionUID = 1L;

    protected String executionId;

    public CompleteAdhocSubProcessCmd(String executionId) {
        this.executionId = executionId;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
        ExecutionEntity execution = executionEntityManager.findById(executionId);
        if (execution == null) {
            throw new FlowableObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
        }

        if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {
            throw new FlowableException("The current flow element of the requested " + execution + " is not an ad-hoc sub process");
        }

        List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
        if (childExecutions.size() > 0) {
            throw new FlowableException("Ad-hoc sub process has running child executions that need to be completed first. " + execution);
        }

        ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
        outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());

        executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);

        CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);

        return null;
    }

}

View on GitHub (pinned to d6d39ce1c6)