{"record":{"id":"89b0ff61425aa8b6","repo":"flowable/flowable-engine","slug":"the-current-flow-element-of-the-requested-execut-89b0ff","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/GetEnabledActivitiesForAdhocSubProcessCmd.java","lineNumber":50,"sourceCode":" */\npublic class GetEnabledActivitiesForAdhocSubProcessCmd implements Command<List<FlowNode>>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String executionId;\n\n    public GetEnabledActivitiesForAdhocSubProcessCmd(String executionId) {\n        this.executionId = executionId;\n    }\n\n    @Override\n    public List<FlowNode> 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        List<FlowNode> enabledFlowNodes = new ArrayList<>();\n\n        // if sequential ordering, only one child execution can be active, so no enabled activities\n        if (adhocSubProcess.hasSequentialOrdering()) {\n            if (execution.getExecutions().size() > 0) {\n                return enabledFlowNodes;\n            }\n        }\n\n        for (FlowElement flowElement : adhocSubProcess.getFlowElements()) {\n            if (flowElement instanceof FlowNode flowNode) {\n                if (flowNode.getIncomingFlows().size() == 0) {\n                    enabledFlowNodes.add(flowNode);\n                }\n            }\n        }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetEnabledActivitiesForAdhocSubProcessCmd.java#L32-L68","documentation":"GetEnabledActivitiesForAdhocSubProcessCmd requires that the execution's current flow element be an AdhocSubProcess. If the execution exists but is parked at any other element (or null element), Flowable throws FlowableException because 'enabled activities' is only meaningful inside an ad-hoc subprocess.","triggerScenarios":"Calling RuntimeService.getEnabledActivitiesForAdhocSubProcess(executionId) where the execution is not currently inside an ad-hoc subprocess — e.g. it sits at a regular user task, service task, or the process has no ad-hoc subprocess at all.","commonSituations":"Passing the root process instance execution instead of the child execution positioned inside the ad-hoc subprocess; calling after the ad-hoc subprocess already completed; process model changed so the element is no longer an ad-hoc subprocess; confusion with the similar dynamic-subprocess APIs.","solutions":["Locate the execution that is currently inside the ad-hoc subprocess: runtimeService.createExecutionQuery().activityId(adhocSubProcessId).singleResult() and use that execution's id.","Check the process definition to confirm the element is declared as an adHocSubProcess.","Call the API while the ad-hoc subprocess is still active, before it completes.","If you needed dynamic sub-process support instead, use the appropriate APIs rather than the ad-hoc one."],"exampleFix":"// before\nruntimeService.getEnabledActivitiesForAdhocSubProcess(processInstanceId);\n// after\nExecution exec = runtimeService.createExecutionQuery()\n    .activityId(\"myAdhocSubProcess\")\n    .processInstanceId(processInstanceId)\n    .singleResult();\nList<FlowNode> nodes = runtimeService.getEnabledActivitiesForAdhocSubProcess(exec.getId());","handlingStrategy":"validation","validationCode":"Execution exec = runtimeService.createExecutionQuery()\n    .executionId(executionId).singleResult();\n// only valid if exec is inside the target ad-hoc subprocess activity","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.getEnabledActivitiesForAdhocSubProcess(executionId);\n} catch (FlowableException e) {\n    // execution is not at an ad-hoc subprocess; look up the correct child execution\n}","preventionTips":["Query executions by activityId of the ad-hoc subprocess to get the right execution","Call only while the subprocess is active","Verify the BPMN model actually declares adHocSubProcess","Don't reuse the root process instance execution for this API"],"tags":["flowable","adhoc-subprocess","wrong-element","invalid-state"],"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"}