{"record":{"id":"527ce813aaae8d42","repo":"flowable/flowable-engine","slug":"no-usertask-instance-found-for-taskentity","errorCode":null,"errorMessage":"No UserTask instance found for \" + taskEntity","messagePattern":"No UserTask instance found for \" \\+ taskEntity","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/InjectParallelUserTaskCmd.java","lineNumber":69,"sourceCode":"\r\n        this.dynamicUserTaskBuilder = dynamicUserTaskBuilder;\r\n    }\r\n\r\n    @Override\r\n    public Void execute(CommandContext commandContext) {\r\n        createDerivedProcessDefinitionForTask(commandContext, taskId);\r\n        return null;\r\n    }\r\n\r\n    @Override\r\n    protected void updateBpmnProcess(CommandContext commandContext, Process process,\r\n            BpmnModel bpmnModel, ProcessDefinitionEntity originalProcessDefinitionEntity, DeploymentEntity newDeploymentEntity) {\r\n        \r\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\r\n        TaskEntity taskEntity = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\r\n        FlowElement flowElement = process.getFlowElement(taskEntity.getTaskDefinitionKey(), true);\r\n        if (!(flowElement instanceof UserTask userTask)) {\r\n            throw new FlowableException(\"No UserTask instance found for \" + taskEntity);\r\n        }\r\n\r\n        SubProcess subProcess = new SubProcess();\r\n        String subProcessId = dynamicUserTaskBuilder.nextSubProcessId(process.getFlowElementMap());\r\n        subProcess.setId(subProcessId);\r\n        subProcess.setName(flowElement.getName());\r\n        \r\n        for (SequenceFlow incomingFlow : userTask.getIncomingFlows()) {\r\n            incomingFlow.setTargetRef(subProcess.getId());\r\n        }\r\n        subProcess.setIncomingFlows(userTask.getIncomingFlows());\r\n        \r\n        for (SequenceFlow outgoingFlow : userTask.getOutgoingFlows()) {\r\n            outgoingFlow.setSourceRef(subProcess.getId());\r\n        }\r\n        subProcess.setOutgoingFlows(userTask.getOutgoingFlows());\r\n        \r\n        userTask.setIncomingFlows(new ArrayList<>());\r","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/InjectParallelUserTaskCmd.java#L51-L87","documentation":"InjectParallelUserTaskCmd.updateBpmnProcess() fetches the task by taskId, resolves its current flow element in the process model, and requires it to be a UserTask. If the resolved FlowElement is a different element type (service task, receive task, sub process, etc.) it throws FlowableException 'No UserTask instance found for <taskEntity>', because parallel user task injection is only valid at user task positions.","triggerScenarios":"Calling the dynamic injection API (DynamicBpmnService / process instance modification) with a taskId whose underlying taskDefinitionKey resolves to a non-UserTask flow element in the deployed BpmnModel.","commonSituations":"Injecting after the process definition changed so the task definition key now maps to a different element; passing an id of a task that is actually inside a service task loop; assuming the active element at any execution point is a user task.","solutions":["Verify the current flow element for the task's taskDefinitionKey is a UserTask before invoking the injection API.","Pick a task id for an actual user task (query taskService.createTaskQuery().taskCandidateGroup... etc.) rather than an arbitrary active execution.","Re-deploy or correct the process definition if the task definition key mapping changed after a model update.","Catch FlowableException and fall back to a different injection point."],"exampleFix":"// before\nprocessInstanceModification.injectParallelUserTask(nonUserTaskId, builder);\n// after\nTaskInfo task = taskService.createTaskQuery().taskId(taskId).singleResult();\nFlowElement el = process.getFlowElement(task.getTaskDefinitionKey(), true);\nif (el instanceof UserTask) {\n    processInstanceModification.injectParallelUserTask(taskId, builder);\n}","handlingStrategy":"validation","validationCode":"FlowElement el = process.getFlowElement(task.getTaskDefinitionKey(), true);\nif (!(el instanceof UserTask)) {\n    throw new IllegalArgumentException(\"Injection point is not a UserTask: \" + task.getTaskDefinitionKey());\n}","typeGuard":"boolean isUserTaskElement(FlowElement el) { return el instanceof UserTask; }","tryCatchPattern":"try {\n    modificationBuilder.injectParallelUserTask(taskId, builder);\n} catch (FlowableException e) {\n    if (e.getMessage().startsWith(\"No UserTask instance found\")) {\n        log.warn(\"Cannot inject parallel user task at non-user-task element for task {}\", taskId);\n    }\n    throw e;\n}","preventionTips":["Pick injection points only at user task executions","Re-validate task definition keys after redeploying changed process definitions","Query active user tasks explicitly before injecting"],"tags":["flowable","dynamic-process-modification","user-task","bpmn-model"],"backgroundTag":"unsupported-operation","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"}