{"record":{"id":"9617d1c01e507b65","repo":"Activiti/Activiti","slug":"could-not-find-a-flowelement-for-activityid-curr","errorCode":null,"errorMessage":"Could not find a FlowElement for activityId ${currentActivityId}","messagePattern":"Could not find a FlowElement for activityId (.+?)","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/delegate/DelegateHelper.java","lineNumber":87,"sourceCode":"    /**\n     * Returns the {@link BpmnModel} matching the process definition bpmn model\n     * for the process definition of the passed {@link DelegateExecution}.\n     */\n    public static BpmnModel getBpmnModel(DelegateExecution execution) {\n        if (execution == null) {\n            throw new ActivitiException(\"Null execution passed\");\n        }\n        return ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId());\n    }\n\n    /**\n     * Returns the current {@link FlowElement} where the {@link DelegateExecution} is currently at.\n     */\n    public static FlowElement getFlowElement(DelegateExecution execution) {\n        BpmnModel bpmnModel = getBpmnModel(execution);\n        FlowElement flowElement = bpmnModel.getFlowElement(execution.getCurrentActivityId());\n        if (flowElement == null) {\n            throw new ActivitiException(\n                \"Could not find a FlowElement for activityId \" + execution.getCurrentActivityId()\n            );\n        }\n        return flowElement;\n    }\n\n    /**\n     * Returns whether or not the provided execution is being use for executing an {@link ExecutionListener}.\n     */\n    public static boolean isExecutingExecutionListener(DelegateExecution execution) {\n        return execution.getCurrentActivitiListener() != null;\n    }\n\n    /**\n     * Returns for the activityId of the passed {@link DelegateExecution} the\n     * {@link Map} of {@link ExtensionElement} instances. These represent the\n     * extension elements defined in the BPMN 2.0 XML as part of that particular\n     * activity.","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/delegate/DelegateHelper.java#L69-L105","documentation":"DelegateHelper.getFlowElement(execution) resolves the FlowElement for the execution's currentActivityId from the process BpmnModel; when the model lookup returns null it throws ActivitiException. This means the execution claims to sit on an activity id that does not exist in the definition's model.","triggerScenarios":"Calling getFlowElement while the execution is not positioned on an activity (currentActivityId null or stale); the activity id belongs to a different process definition (mismatched model lookup via execution.getProcessDefinitionId()); dynamic/modified process instances after a redeployment.","commonSituations":"Task/execution listeners attached to a process that was redeployed with renamed ids while old instances still run; calling the helper inside a listener where the execution is between activities (e.g. on sequence-flow take or end listeners); call-activity child executions resolved against the parent's model.","solutions":["Only call getFlowElement from contexts where the execution is positioned on a concrete activity (start of a task listener, ExecutionListener EVENTNAME_START on the activity).","Log execution.getCurrentActivityId() and execution.getProcessDefinitionId() and confirm the id exists in that deployment's BPMN XML.","Handle legacy instances explicitly: guard with bpmnModel.getFlowElement(id) == null and skip/fallback instead of throwing."],"exampleFix":"// before\nFlowElement el = DelegateHelper.getFlowElement(execution); // throws when id missing\n// after\nBpmnModel model = DelegateHelper.getBpmnModel(execution);\nFlowElement el = model.getFlowElement(execution.getCurrentActivityId());\nif (el == null) {\n    logger.warn(\"No flow element for \" + execution.getCurrentActivityId());\n    return;\n}","handlingStrategy":"try-catch","validationCode":"BpmnModel model = DelegateHelper.getBpmnModel(execution);\nif (execution.getCurrentActivityId() == null || model.getFlowElement(execution.getCurrentActivityId()) == null) {\n    return; // execution not positioned on a resolvable activity\n}","typeGuard":"boolean hasCurrentFlowElement(DelegateExecution e) {\n    return e.getCurrentActivityId() != null\n        && DelegateHelper.getBpmnModel(e).getFlowElement(e.getCurrentActivityId()) != null;\n}","tryCatchPattern":"try {\n    FlowElement el = DelegateHelper.getFlowElement(execution);\n} catch (ActivitiException e) {\n    logger.warn(\"No FlowElement for activity {} on definition {}\",\n        execution.getCurrentActivityId(), execution.getProcessDefinitionId());\n}","preventionTips":["Call getFlowElement only from activity-scoped listeners (start events, task create)","Watch for old instances after redeploying processes with renamed ids","Log activityId + processDefinitionId when handling model lookups"],"tags":["bpmn-model","activity-id","resource-not-found","process-definition"],"backgroundTag":"entity-not-found","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}