{"record":{"id":"2ea164c8f7016826","repo":"flowable/flowable-engine","slug":"could-not-find-task-entity-for-id","errorCode":null,"errorMessage":"Could not find task entity for id ","messagePattern":"Could not find task entity for id ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CompleteTaskCmd.java","lineNumber":86,"sourceCode":"    \n    public CompleteTaskCmd(String taskId, String userId, Map<String, Object> variables, Map<String, Object> variablesLocal,\n            Map<String, Object> transientVariables, Map<String, Object> transientVariablesLocal) {\n        \n        this(taskId, variables, variablesLocal, transientVariables, transientVariablesLocal);\n        this.userId = userId;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        \n        if (taskId == null) {\n            throw new FlowableIllegalArgumentException(\"Null task id\");\n        }\n        \n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        TaskEntity taskEntity = cmmnEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n        if (taskEntity == null) {\n            throw new FlowableObjectNotFoundException(\"Could not find task entity for id \" + taskId, TaskEntity.class);\n        }\n        \n        if (StringUtils.isNotEmpty(taskEntity.getProcessInstanceId())) {\n            throw new FlowableException(taskEntity + \" is created by the process engine and should be completed via the process engine API\");\n        }\n        \n        String planItemInstanceId = taskEntity.getSubScopeId();\n        PlanItemInstanceEntity planItemInstanceEntity = null;\n        if (planItemInstanceId != null) {\n            planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findById(planItemInstanceId);\n            if (planItemInstanceEntity == null) {\n                throw new FlowableException(\"Could not find plan item instance for \" + taskEntity);\n            }\n        }\n        \n        if (variables != null) {\n            taskEntity.setVariables(variables);\n        }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CompleteTaskCmd.java#L68-L104","documentation":"Thrown by CMMN's CompleteTaskCmd when no TaskEntity exists in the task service for the given taskId. The CMMN engine requires an existing standalone (non-process) task to complete; a missing task means the id is wrong, the task was already completed/deleted, or the task belongs to a different engine/database. This is a FlowableObjectNotFoundException carrying TaskEntity.class as the entity type.","triggerScenarios":"Calling CmmnTaskService.completeTask(taskId) (or an equivalent CompleteTaskCmd) with a taskId that does not exist: typo, task already completed and deleted, task from the BPMN process engine, or wrong tenant/database in a multi-datasource setup.","commonSituations":"Reusing a stale task id after the case task was completed; completing a process-engine task via the CMMN API; querying a different database/schema than the one holding the task; copying ids from a test fixture without seeding them.","solutions":["Verify the taskId exists before completing, e.g. taskService.createTaskQuery().taskId(id).singleResult() != null.","If the task was created by the BPMN engine, complete it via the process engine's TaskService (RuntimeService/TaskService.complete) instead.","Check you are connected to the correct database/schema/tenant where the task was created.","Ensure the task was not already completed in a concurrent step; fetch it fresh in the same transaction."],"exampleFix":"// before\ncmmnTaskService.completeTask(taskId);\n// after\nguard: org.flowable.task.api.Task t = cmmnTaskService.createTaskQuery().taskId(taskId).singleResult();\nif (t == null) throw new IllegalStateException(\"Task \" + taskId + \" does not exist (already completed or wrong engine?)\");\ncmmnTaskService.completeTask(taskId);","handlingStrategy":"validation","validationCode":"org.flowable.task.api.Task t = cmmnTaskService.createTaskQuery().taskId(taskId).singleResult();\nif (t == null) {\n    throw new IllegalStateException(\"No CMMN task with id \" + taskId);\n}\ncmmnTaskService.completeTask(taskId);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch the task fresh in the same transaction/unit of work before completing.","Never cache task ids across long-running flows; tasks disappear once completed.","Route tasks by origin engine (processInstanceId present -> BPMN TaskService)."],"tags":["cmmn","task-not-found","flowable","entity-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}