{"record":{"id":"58c81c61007c3534","repo":"flowable/flowable-engine","slug":"task-not-found-with-id-taskid","errorCode":null,"errorMessage":"Task not found with id ${taskId}","messagePattern":"Task not found with id (.+?)","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetTaskFormModelCmd.java","lineNumber":72,"sourceCode":"    @Override\n    public FormInfo execute(CommandContext commandContext) {\n        FormService formService = CommandContextUtil.getFormService();\n        if (formService == null) {\n            throw new FlowableIllegalArgumentException(\"Form engine is not initialized\");\n        }\n\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        TaskInfo task = cmmnEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n        Date endTime = null;\n        if (task == null) {\n            task = cmmnEngineConfiguration.getTaskServiceConfiguration().getHistoricTaskService().getHistoricTask(taskId);\n            if (task != null) {\n                endTime = ((HistoricTaskInstance) task).getEndTime();\n            }\n        }\n        \n        if (task == null) {\n            throw new FlowableObjectNotFoundException(\"Task not found with id \" + taskId);\n        }\n\n        Map<String, Object> variables = new HashMap<>();\n        if (!ignoreVariables && task.getScopeId() != null) {\n            List<HistoricVariableInstance> variableInstances = cmmnEngineConfiguration.getCmmnHistoryService()\n                    .createHistoricVariableInstanceQuery()\n                    .caseInstanceId(task.getScopeId())\n                    .list();\n\n            for (HistoricVariableInstance historicVariableInstance : variableInstances) {\n                variables.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue());\n            }\n        }\n\n        String parentDeploymentId = null;\n        if (StringUtils.isNotEmpty(task.getScopeDefinitionId())) {\n            PlanItemDefinition itemDefinition = CaseDefinitionUtil.getCmmnModel(task.getScopeDefinitionId()).findPlanItemDefinition(task.getTaskDefinitionKey());\n            boolean sameDeployment = true;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetTaskFormModelCmd.java#L54-L90","documentation":"GetTaskFormModelCmd throws FlowableObjectNotFoundException when no task (runtime or historic) exists for the given taskId. The command checks the runtime task and falls back to historic task lookup before throwing.","triggerScenarios":"Calling cmmnTaskService.getTaskFormModel(taskId) with an id that matches neither a running CMMN task nor a historic task — deleted, completed-and-purged, or simply wrong id.","commonSituations":"Passing a BPMN task id to the CMMN task service (different task tables); using an id after history cleanup removed the historic task; typos or stale references from another environment's database.","solutions":["Confirm the task exists: cmmnTaskService.createTaskQuery().taskId(id).singleResult() or cmmnHistoryService.createHistoricTaskInstanceQuery().taskId(id)","Use the CMMN task service (not the BPMN one) for CMMN task ids","If tasks were purged by history cleanup, the form model is no longer retrievable — fetch forms before cleanup or persist them separately","Check the taskId comes from the same database/tenant environment"],"exampleFix":"// before\nFormInfo info = cmmnTaskService.getTaskFormModel(taskId); // throws if task absent\n// after\nTask t = cmmnTaskService.createTaskQuery().taskId(taskId).singleResult();\nHistoricTaskInstance ht = t == null ? cmmnHistoryService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult() : null;\nif (t != null || ht != null) {\n    FormInfo info = cmmnTaskService.getTaskFormModel(taskId);\n}","handlingStrategy":"validation","validationCode":"Task t = cmmnTaskService.createTaskQuery().taskId(taskId).singleResult();\nHistoricTaskInstance ht = (t == null) ? cmmnHistoryService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult() : null;\nif (t == null && ht == null) {\n    throw new IllegalArgumentException(\"No such CMMN task: \" + taskId);\n}","typeGuard":"boolean taskExists(String taskId) {\n    return taskId != null && (cmmnTaskService.createTaskQuery().taskId(taskId).count() > 0\n        || cmmnHistoryService.createHistoricTaskInstanceQuery().taskId(taskId).count() > 0);\n}","tryCatchPattern":"try {\n    FormInfo info = cmmnTaskService.getTaskFormModel(taskId);\n} catch (FlowableObjectNotFoundException e) {\n    // task absent (runtime and historic): return 404\n}","preventionTips":["Use the CMMN task service for CMMN task ids, not the BPMN one","Fetch form models before history cleanup purges tasks","Null-check query results before dereferencing ids"],"tags":["cmmn","tasks","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-18T11:17:12.947Z"}