{"record":{"id":"90a98981bb55a713","repo":"flowable/flowable-engine","slug":"task-not-found-with-id","errorCode":null,"errorMessage":"Task not found with id ","messagePattern":"Task not found with id ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetTaskFormModelCmd.java","lineNumber":74,"sourceCode":"\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        FormService formService = CommandContextUtil.getFormService();\n        if (formService == null) {\n            throw new FlowableIllegalArgumentException(\"Form engine is not initialized\");\n        }\n\n        TaskInfo task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n        Date endTime = null;\n        if (task == null) {\n            historic = true;\n            task = processEngineConfiguration.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.getProcessInstanceId() != null) {\n\n            if (!historic) {\n                processEngineConfiguration.getTaskService()\n                        .getVariableInstances(taskId).values()\n                        .stream()\n                        .forEach(variableInstance -> variables.putIfAbsent(variableInstance.getName(), variableInstance.getValue()));\n\n                processEngineConfiguration.getRuntimeService().getVariableInstances(task.getProcessInstanceId()).values()\n                        .stream()\n                        .forEach(variableInstance -> variables.putIfAbsent(variableInstance.getName(), variableInstance.getValue()));\n\n\n            } else {\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetTaskFormModelCmd.java#L56-L92","documentation":"FlowableObjectNotFoundException thrown by GetTaskFormModelCmd.execute when no task exists for the given taskId. The command looks up the task (runtime or historic depending on the 'historic' flag) and aborts before building the form model. It signals a caller-supplied identifier that does not reference any task in the engine database.","triggerScenarios":"Calling TaskService.getTaskFormModel(taskId) (or formService equivalents) with a taskId that is null-like-but-nonnull garbage, already completed-and-deleted, mistyped, or from a different engine/database when historic=false and no historic task exists either.","commonSituations":"REST/API callers caching stale task ids after task completion; querying with a historic task id while historic=false; multi-tenant setups where the id exists in another tenant's data; typos or id truncation when wiring ids through integration code.","solutions":["Verify the taskId exists via taskService.createTaskQuery().taskId(id).singleResult() or HistoricTaskInstanceQuery before fetching the form model","If the task may be completed, query the historic task and set historic=true in the form model options","Check you are connected to the same database/schema/tenant where the task was created","Catch FlowableObjectNotFoundException and return a 404-style response instead of a 500"],"exampleFix":"// before\nFormInfo form = taskService.getTaskFormModel(taskId); // throws if task gone\n// after\nTask t = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (t == null) {\n    HistoricTaskInstance h = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();\n    if (h == null) throw new NotFoundException(\"No task \" + taskId);\n}\nFormInfo form = taskService.getTaskFormModel(taskId, true);","handlingStrategy":"try-catch","validationCode":"boolean exists = taskService.createTaskQuery().taskId(taskId).count() > 0\n        || historyService.createHistoricTaskInstanceQuery().taskId(taskId).count() > 0;","typeGuard":null,"tryCatchPattern":"try {\n    FormInfo form = taskService.getTaskFormModel(taskId);\n} catch (FlowableObjectNotFoundException e) {\n    respond(404, \"Task or form not found: \" + e.getMessage());\n}","preventionTips":["Resolve task ids from engine queries, never from client-supplied stale state","Prefer the historic=true form model variant when tasks may be completed","Keep form definitions deployed together with the process definitions that reference them"],"tags":["flowable","task-not-found","form-model"],"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"}