{"record":{"id":"dd9b17170dcc5f80","repo":"flowable/flowable-engine","slug":"no-task-found-for-taskid-dd9b17","errorCode":null,"errorMessage":"No task found for taskId ''","messagePattern":"No task found for taskId ''","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetTaskFormCmd.java","lineNumber":45,"sourceCode":"/**\n * @author Tom Baeyens\n */\npublic class GetTaskFormCmd implements Command<TaskFormData>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String taskId;\n\n    public GetTaskFormCmd(String taskId) {\n        this.taskId = taskId;\n    }\n\n    @Override\n    public TaskFormData execute(CommandContext commandContext) {\n        TaskEntity task = commandContext\n                .getTaskEntityManager()\n                .findTaskById(taskId);\n        if (task == null) {\n            throw new ActivitiObjectNotFoundException(\"No task found for taskId '\" + taskId + \"'\", Task.class);\n        }\n\n        if (task.getTaskDefinition() != null) {\n            TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();\n            if (taskFormHandler == null) {\n                throw new ActivitiException(\"No taskFormHandler specified for task '\" + taskId + \"'\");\n            }\n\n            return taskFormHandler.createTaskForm(task);\n        } else {\n            // Standalone task, no TaskFormData available\n            return null;\n        }\n    }\n\n}\n","sourceCodeStart":27,"sourceCodeEnd":62,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetTaskFormCmd.java#L27-L62","documentation":"GetTaskFormCmd looks up the task by taskId via the task entity manager and throws ActivitiObjectNotFoundException when findTaskById returns null. This means the taskId passed to the TaskService.getTaskForm API does not correspond to any persisted task row. The exception carries Task.class so callers can detect the missing entity type.","triggerScenarios":"Calling taskService.getTaskForm(taskId) with an id for a task that was deleted, completed (and removed by history level cleanup), never created, or with an id belonging to a different engine/database.","commonSituations":"Stale task ids cached in a UI after the task was completed; calling with an execution id instead of a task id; multi-database setups where the id belongs to another schema; tests using fabricated ids like \"12345\".","solutions":["Verify the taskId with taskService.createTaskQuery().taskId(taskId).singleResult() before requesting the form.","Confirm you are using the actual task id, not the execution or process instance id.","Check you are connected to the same database/engine that owns the task.","Catch ActivitiObjectNotFoundException and surface a 'task no longer exists' message to the user."],"exampleFix":"// before\nTaskFormData form = taskService.getTaskForm(staleTaskId);\n// after\nTask task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task != null) {\n    TaskFormData form = taskService.getTaskForm(taskId);\n} else {\n    logger.warn(\"Task {} no longer exists, refreshing task list\", taskId);\n}","handlingStrategy":"validation","validationCode":"boolean exists = taskService.createTaskQuery().taskId(taskId).count() > 0;\nif (!exists) throw new IllegalStateException(\"Task \" + taskId + \" not found\");","typeGuard":null,"tryCatchPattern":"try {\n    TaskFormData form = taskService.getTaskForm(taskId);\n} catch (ActivitiObjectNotFoundException e) {\n    // e.getObjectClass() == Task.class: task missing; refresh task list\n}","preventionTips":["Always obtain task ids from taskService query results, never hard-code them.","Refresh cached task ids after task completion events.","Distinguish task ids from execution/process instance ids in your DTOs."],"tags":["task","not-found","workflow"],"backgroundTag":"record-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"}