{"record":{"id":"6d752e6e018db735","repo":"flowable/flowable-engine","slug":"the-current-flow-element-of-the-requested-execut","errorCode":null,"errorMessage":"The current flow element of the requested ${execution} is not an ad-hoc sub process","messagePattern":"The current flow element of the requested (.+?) is not an ad-hoc sub process","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/ExecuteActivityForAdhocSubProcessCmd.java","lineNumber":51,"sourceCode":"\n    private static final long serialVersionUID = 1L;\n    protected String executionId;\n    protected String activityId;\n\n    public ExecuteActivityForAdhocSubProcessCmd(String executionId, String activityId) {\n        this.executionId = executionId;\n        this.activityId = activityId;\n    }\n\n    @Override\n    public Execution execute(CommandContext commandContext) {\n        ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(executionId);\n        if (execution == null) {\n            throw new FlowableObjectNotFoundException(\"No execution found for id '\" + executionId + \"'\", ExecutionEntity.class);\n        }\n\n        if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess adhocSubProcess)) {\n            throw new FlowableException(\"The current flow element of the requested \" + execution + \" is not an ad-hoc sub process\");\n        }\n\n        FlowNode foundNode = null;\n\n        // if sequential ordering, only one child execution can be active\n        if (adhocSubProcess.hasSequentialOrdering()) {\n            if (execution.getExecutions().size() > 0) {\n                throw new FlowableException(\"Sequential ad-hoc sub process in \" + execution + \" already has an active execution\");\n            }\n        }\n\n        for (FlowElement flowElement : adhocSubProcess.getFlowElements()) {\n            if (activityId.equals(flowElement.getId()) && flowElement instanceof FlowNode flowNode) {\n                if (flowNode.getIncomingFlows().size() == 0) {\n                    foundNode = flowNode;\n                }\n            }\n        }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/ExecuteActivityForAdhocSubProcessCmd.java#L33-L69","documentation":"This command only works when the execution's current flow element is an AdhocSubProcess. If the execution points at any other element (or none), execute() throws FlowableException because ad-hoc activity execution is only valid inside an ad-hoc subprocess.","triggerScenarios":"Invoking ExecuteActivityForAdhocSubProcessCmd with an execution whose currentFlowElement is a regular subprocess, user task, process definition, or is null.","commonSituations":"Passing the parent process instance execution instead of the execution running inside the ad-hoc subprocess; process definition changed after deployment so the element under the execution is no longer ad-hoc.","solutions":["Locate the child execution inside the ad-hoc subprocess: runtimeService.createExecutionQuery().processInstanceId(pid).activityId(adhocSubProcessId)","Verify the process model actually contains an adhocSubProcess element and the execution is currently inside it","Redeploy/update the BPMN if the model was changed and executions are stuck on old definitions"],"exampleFix":"// before\nmanagementService.executeCommand(new ExecuteActivityForAdhocSubProcessCmd(processInstanceId, \"callActivity1\"));\n// after\nExecution adhocExec = runtimeService.createExecutionQuery()\n    .processInstanceId(processInstanceId).activityId(\"adhocSubProcess1\").singleResult();\nmanagementService.executeCommand(new ExecuteActivityForAdhocSubProcessCmd(adhocExec.getId(), \"callActivity1\"));","handlingStrategy":"validation","validationCode":"Execution adhocExec = runtimeService.createExecutionQuery().processInstanceId(pid).activityId(adhocSubProcessId).singleResult();\nif (adhocExec == null) throw new IllegalArgumentException(\"execution not inside ad-hoc subprocess\");","typeGuard":"boolean isAdhocExecution(Execution e) { return ((ExecutionEntity) e).getCurrentFlowElement() instanceof AdhocSubProcess; }","tryCatchPattern":"try { ... } catch (FlowableException e) { if (e.getMessage().contains(\"not an ad-hoc sub process\")) { /* locate correct child execution */ } else throw e; }","preventionTips":["Model inspection: confirm the element under the execution is an adhocSubProcess","Query child executions by activityId instead of reusing the parent id","Re-inspect after process definition version changes"],"tags":["flowable","adhoc-subprocess","wrong-element"],"backgroundTag":"invalid-state-transition","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}