{"record":{"id":"0eaaba0b51fa20ef","repo":"flowable/flowable-engine","slug":"no-usertask-instance-found-for-task-definition-key","errorCode":null,"errorMessage":"No UserTask instance found for task definition key \" + taskEntity.getTaskDefinitionKey()","messagePattern":"No UserTask instance found for task definition key \" \\+ taskEntity\\.getTaskDefinitionKey\\(\\)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/DynamicSubProcessJoinInjectUtil.java","lineNumber":56,"sourceCode":"import org.flowable.engine.impl.persistence.entity.ResourceEntity;\r\nimport org.flowable.engine.impl.util.CommandContextUtil;\r\nimport org.flowable.engine.impl.util.ProcessDefinitionUtil;\r\nimport org.flowable.engine.repository.ProcessDefinition;\r\nimport org.flowable.task.service.impl.persistence.entity.TaskEntity;\r\n\r\n/**\r\n * @author Tijs Rademakers\r\n */\r\npublic class DynamicSubProcessJoinInjectUtil extends BaseDynamicSubProcessInjectUtil {\r\n    \r\n    public static void injectSubProcessWithJoin(String taskId, Process process, BpmnModel bpmnModel, DynamicEmbeddedSubProcessBuilder dynamicEmbeddedSubProcessBuilder,\r\n                    ProcessDefinitionEntity originalProcessDefinitionEntity, DeploymentEntity newDeploymentEntity, CommandContext commandContext) {\r\n        \r\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\r\n        TaskEntity taskEntity = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\r\n        FlowElement taskFlowElement = process.getFlowElement(taskEntity.getTaskDefinitionKey(), true);\r\n        if (!(taskFlowElement instanceof UserTask userTask)) {\r\n            throw new FlowableException(\"No UserTask instance found for task definition key \" + taskEntity.getTaskDefinitionKey());\r\n        }\r\n\r\n        if (dynamicEmbeddedSubProcessBuilder.getId() != null && process.getFlowElement(dynamicEmbeddedSubProcessBuilder.getId(), true) != null) {\r\n            throw new FlowableIllegalArgumentException(\"Invalid sub-process identifier: identifier already exists in host process definition\");\r\n        }\r\n        \r\n        GraphicInfo elementGraphicInfo = bpmnModel.getGraphicInfo(userTask.getId());\r\n        \r\n        SubProcess parentSubProcess = new SubProcess();\r\n        String subProcessId = dynamicEmbeddedSubProcessBuilder.nextSubProcessId(process.getFlowElementMap());\r\n        parentSubProcess.setId(subProcessId);\r\n        parentSubProcess.setName(userTask.getName());\r\n        \r\n        for (SequenceFlow incomingFlow : userTask.getIncomingFlows()) {\r\n            incomingFlow.setTargetRef(parentSubProcess.getId());\r\n        }\r\n        parentSubProcess.setIncomingFlows(userTask.getIncomingFlows());\r\n        \r","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/DynamicSubProcessJoinInjectUtil.java#L38-L74","documentation":"Thrown by DynamicSubProcessJoinInjectUtil.injectSubProcessWithJoin when dynamically injecting an embedded subprocess at a running task: the task identified by taskId does not resolve to a UserTask flow element in the process model. The injection algorithm anchors the new subprocess around a user task, so any other element type (service task, gateway, etc.) is rejected.","triggerScenarios":"Calling DynamicBpmnService-style dynamic injection (injectSubProcessWithJoin) with a taskId whose task definition key points at a non-UserTask element, or a task definition key that is missing/stale in the process model (getFlowElement returns null or another FlowElement).","commonSituations":"Passing a standalone-task id that has no matching activity in the model; the process definition was changed so the task definition key no longer maps to the UserTask; injecting at an automatically executed task instead of a user task.","solutions":["Pass the taskId of an active UserTask whose task definition key exists as a UserTask in the current process definition","Verify process.getFlowElement(taskEntity.getTaskDefinitionKey(), true) resolves to a UserTask in the deployed BPMN","Redeploy or reference the correct process definition if the model and runtime are out of sync","Use an injection API suited to non-user-task anchors instead of the join-injection utility"],"exampleFix":"// before\ninjectSubProcessWithJoin(serviceTaskTaskId, builder, ...); // service task, fails\n// after\nTask task = taskService.createTaskQuery().taskCandidateUser(user).singleResult(); // must be a UserTask\ninjectSubProcessWithJoin(task.getId(), builder, ...);","handlingStrategy":"validation","validationCode":"Task task = taskService.createTaskQuery().taskId(taskId).singleResult();\nFlowElement el = process.getFlowElement(task.getTaskDefinitionKey(), true);\nif (!(el instanceof UserTask)) throw new IllegalArgumentException(\"taskId must anchor on a UserTask\");","typeGuard":"static boolean isUserTaskAnchor(Process process, TaskEntity task) {\n    return process.getFlowElement(task.getTaskDefinitionKey(), true) instanceof UserTask;\n}","tryCatchPattern":"try {\n    injectSubProcessWithJoin(taskId, builder, process, bpmnModel, def, deployment, commandContext);\n} catch (FlowableException ex) {\n    if (ex.getMessage().startsWith(\"No UserTask instance found\")) {\n        // pick a UserTask-anchored taskId\n    } else throw ex;\n}","preventionTips":["Only invoke join-injection on tasks whose definition key is a UserTask in the model","Re-resolve the process definition after any dynamic model change","Avoid injecting at auto-completed or service tasks","Assert task definition key presence in the deployed BPMN first"],"tags":["dynamic-bpmn","usertask","subprocess-injection","flowable"],"backgroundTag":"invalid-argument-value","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}