{"record":{"id":"c1b231d0288a1a8e","repo":"flowable/flowable-engine","slug":"taskid-is-null-c1b231","errorCode":null,"errorMessage":"taskId is null","messagePattern":"taskId is null","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetTaskVariableCmd.java","lineNumber":45,"sourceCode":" * @author Joram Barrez\n */\npublic class GetTaskVariableCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String taskId;\n    protected String variableName;\n    protected boolean isLocal;\n\n    public GetTaskVariableCmd(String taskId, String variableName, boolean isLocal) {\n        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 ActivitiIllegalArgumentException(\"taskId is null\");\n        }\n        if (variableName == null) {\n            throw new ActivitiIllegalArgumentException(\"variableName is null\");\n        }\n\n        TaskEntity task = commandContext\n                .getTaskEntityManager()\n                .findTaskById(taskId);\n\n        if (task == null) {\n            throw new ActivitiObjectNotFoundException(\"task \" + taskId + \" doesn't exist\", Task.class);\n        }\n\n        Object value;\n\n        if (isLocal) {\n            value = task.getVariableLocal(variableName, false);\n        } else {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetTaskVariableCmd.java#L27-L63","documentation":"GetTaskVariableCmd.execute validates its inputs first and throws ActivitiIllegalArgumentException when taskId is null. The library refuses to issue a database lookup with a null identifier. It is a cheap fail-fast guard, so the error always indicates a caller-side bug.","triggerScenarios":"Calling taskService.getVariable(taskId, variableName) or getVariableLocal with a null taskId, typically when the id comes from an uninitialized variable, an empty optional, or a missing form/query parameter.","commonSituations":"REST endpoints that skip null checks on path parameters; beans whose task id field was never set; migrating code where the task was fetched first and its id propagated but is null on early failure paths.","solutions":["Assert the taskId is non-null before calling taskService.getVariable/getVariableLocal.","Fix the upstream code path that produced a null id (uninitialized field, unbound request parameter).","Return a 400-style validation error to callers instead of letting the engine throw.","For optional task lookups, first check task existence and skip the variable fetch when absent."],"exampleFix":"// before\nObject value = taskService.getVariable(taskId, \"status\");\n// after\nif (taskId == null) {\n    throw new IllegalArgumentException(\"taskId is required\");\n}\nObject value = taskService.getVariable(taskId, \"status\");","handlingStrategy":"validation","validationCode":"if (taskId == null) throw new IllegalArgumentException(\"taskId must not be null\");","typeGuard":null,"tryCatchPattern":"try {\n    return taskService.getVariable(taskId, name);\n} catch (ActivitiIllegalArgumentException e) {\n    if (e.getMessage().equals(\"taskId is null\")) return null;\n    throw e;\n}","preventionTips":["Use Objects.requireNonNull on ids at API boundaries.","Avoid optional unwrap chains that can yield null ids.","Log the call site when a null id is detected to find the producer."],"tags":["null","task","validation"],"backgroundTag":"null-argument","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"}