{"record":{"id":"0e1c62291e4d8b28","repo":"flowable/flowable-engine","slug":"task-0e1c62","errorCode":null,"errorMessage":"task ","messagePattern":"task ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetTaskVariableCmd.java","lineNumber":57,"sourceCode":"        this.taskId = taskId;\n        this.variableName = variableName;\n        this.isLocal = isLocal;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (taskId == null) {\n            throw new FlowableIllegalArgumentException(\"taskId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variableName is null\");\n        }\n\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        TaskEntity task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n\n        if (task == null) {\n            throw new FlowableObjectNotFoundException(\"task \" + taskId + \" doesn't exist\", Task.class);\n        }\n\n        Object value;\n\n        if (isLocal) {\n            value = task.getVariableLocal(variableName, false);\n        } else {\n            value = task.getVariable(variableName, false);\n        }\n\n        return value;\n    }\n}\n","sourceCodeStart":39,"sourceCodeEnd":71,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetTaskVariableCmd.java#L39-L71","documentation":"FlowableObjectNotFoundException (with Task.class as the referenced entity) thrown by GetTaskVariableCmd.execute after the task lookup returns null. Unlike the null guards, the taskId was supplied but does not match any persisted task. The exception carries the missing entity type so callers can distinguish task-not-found from variable-not-found.","triggerScenarios":"taskService.getTaskVariable(taskId, name) / getVariableLocal with a taskId that is stale, completed-and-cascaded-away, or from another database; race where the task is deleted between listing and fetching its variable.","commonSituations":"Async workers processing task ids from a queue after the task was already handled elsewhere; environments pointing at different DBs (test vs prod); process instances ended with history cleanup removing the task.","solutions":["Confirm task existence with taskService.createTaskQuery().taskId(taskId).singleResult() first","Check the application connects to the same database/schema where the task lives","Handle completed tasks via the history service (HistoricTaskInstanceQuery) if variables must be read after completion","Catch FlowableObjectNotFoundException and treat it as a 404 in service/API layers"],"exampleFix":"// before\nObject v = taskService.getTaskVariable(taskId, \"amount\");\n// after\nif (taskService.createTaskQuery().taskId(taskId).count() == 0) {\n    throw new NotFoundException(\"Task \" + taskId + \" not found\");\n}\nObject v = taskService.getTaskVariable(taskId, \"amount\");","handlingStrategy":"try-catch","validationCode":"boolean exists = taskService.createTaskQuery().taskId(taskId).count() > 0;","typeGuard":null,"tryCatchPattern":"try {\n    Object v = taskService.getTaskVariable(taskId, name);\n} catch (FlowableObjectNotFoundException e) {\n    respond(404, \"Task \" + taskId + \" does not exist\");\n}","preventionTips":["Re-verify task existence right before variable access in long-running flows","Handle completed tasks through history queries","Ensure consistent database configuration across environments"],"tags":["flowable","task-not-found","variables"],"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"}