{"record":{"id":"45da1bfc066b210d","repo":"flowable/flowable-engine","slug":"task-is-null-45da1b","errorCode":null,"errorMessage":"task is null","messagePattern":"task is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/SaveTaskCmd.java","lineNumber":55,"sourceCode":"import org.flowable.task.service.impl.persistence.entity.TaskEntity;\n\n/**\n * @author Joram Barrez\n */\npublic class SaveTaskCmd implements Command<Void>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    protected TaskEntity task;\n\n    public SaveTaskCmd(Task task) {\n        this.task = (TaskEntity) task;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (task == null) {\n            throw new FlowableIllegalArgumentException(\"task is null\");\n        }\n\n        if (task.getProcessDefinitionId() != null && Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, task.getProcessDefinitionId())) {\n            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();\n            compatibilityHandler.saveTask(task);\n            return null;\n        }\n        \n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        TaskService taskService = processEngineConfiguration.getTaskServiceConfiguration().getTaskService();\n\n        if (task.getRevision() == 0) {\n            TaskHelper.insertTask(task, null, true, false);\n\n            FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();\n            if (eventDispatcher != null && eventDispatcher.isEnabled()) {\n                processEngineConfiguration.getEventDispatcher().dispatchEvent(FlowableTaskEventBuilder.createEntityEvent(FlowableEngineEventType.TASK_CREATED, task),\n                        processEngineConfiguration.getEngineCfgKey());","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/SaveTaskCmd.java#L37-L73","documentation":"SaveTaskCmd.execute throws FlowableIllegalArgumentException when the task passed to the command is null. The command persists changes to a TaskEntity, so a null task cannot be processed. This is the first validation in the command before any Flowable5 compatibility dispatching.","triggerScenarios":"Calling taskService.saveTask(null) or executing new SaveTaskCmd(null).","commonSituations":"taskService.createTaskQuery()...singleResult() returned null (task not found) and the null result was passed to saveTask; a task variable was reassigned/cleared before saving; API misuse in test code.","solutions":["Pass a non-null Task (typically a TaskEntity obtained from a task query) to saveTask.","Verify singleResult() / a task lookup returned a task before calling saveTask.","Use taskService.newTask() to create a new task rather than passing null."],"exampleFix":"// before\nTask task = taskService.createTaskQuery().taskId(id).singleResult();\ntaskService.saveTask(task); // NPE/flowable error if not found\n// after\nTask task = taskService.createTaskQuery().taskId(id).singleResult();\nif (task != null) {\n    taskService.saveTask(task);\n}","handlingStrategy":"validation","validationCode":"Task task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task == null) {\n    throw new IllegalArgumentException(\"Task \" + taskId + \" not found\");\n}\ntaskService.saveTask(task);","typeGuard":"boolean isTaskPresent = task != null && task.getId() != null;","tryCatchPattern":null,"preventionTips":["Never pass query singleResult() output to saveTask unchecked.","Use taskService.newTask() to create tasks rather than fabricating nulls.","Centralize task lookups in helpers that fail fast on missing tasks."],"tags":["flowable","null-argument","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-14T11:17:12.474Z"}