{"record":{"id":"be78cf20dd391623","repo":"flowable/flowable-engine","slug":"task-id-should-not-be-null","errorCode":null,"errorMessage":"Task id should not be null","messagePattern":"Task id should not be null","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetRenderedTaskFormCmd.java","lineNumber":51,"sourceCode":" * @author Tom Baeyens\n * @author Joram Barrez\n */\npublic class GetRenderedTaskFormCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String taskId;\n    protected String formEngineName;\n\n    public GetRenderedTaskFormCmd(String taskId, String formEngineName) {\n        this.taskId = taskId;\n        this.formEngineName = formEngineName;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n\n        if (taskId == null) {\n            throw new FlowableIllegalArgumentException(\"Task id should not be null\");\n        }\n\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        TaskEntity task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n        if (task == null) {\n            throw new FlowableObjectNotFoundException(\"Task '\" + taskId + \"' not found\", Task.class);\n        }\n\n        FormHandlerHelper formHandlerHelper = processEngineConfiguration.getFormHandlerHelper();\n        TaskFormHandler taskFormHandler = formHandlerHelper.getTaskFormHandlder(task);\n        if (taskFormHandler != null) {\n\n            FormEngine formEngine = processEngineConfiguration.getFormEngines().get(formEngineName);\n\n            if (formEngine == null) {\n                throw new FlowableException(\"No formEngine '\" + formEngineName + \"' defined process engine configuration\");\n            }\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetRenderedTaskFormCmd.java#L33-L69","documentation":"FlowableIllegalArgumentException thrown by GetRenderedTaskFormCmd.execute as a precondition check: the taskId supplied to the command is null. Nothing is looked up; the command fails fast because rendering a task form is impossible without a task id.","triggerScenarios":"Calling formService.getRenderedTaskForm(taskId) (with or without a form engine name) passing null — typically an uninitialized variable, a Task object whose getId() returned null, or an unsaved transient task.","commonSituations":"Passing task.getId() of a task created in Java but not yet saved through the task service; a mapping layer that dropped the id; forgetting to assign the result of taskService.createTaskQuery() before rendering the form.","solutions":["Ensure a non-null task id is passed: obtain it from taskService.createTaskQuery()...singleResult().getId() or from a persisted TaskEntity.","Add a null/blank check in the calling code before invoking the form API.","If the task is created programmatically, call taskService.saveTask(task) first so it receives a database id."],"exampleFix":"// before\nString id = myTask != null ? myTask.getId() : null;\nObject form = formService.getRenderedTaskForm(id);\n// after\nif (myTask == null || myTask.getId() == null) {\n    throw new IllegalArgumentException(\"A persisted task is required\");\n}\nObject form = formService.getRenderedTaskForm(myTask.getId());","handlingStrategy":"validation","validationCode":"if (taskId == null || taskId.isBlank()) {\n    throw new IllegalArgumentException(\"taskId must be a persisted, non-null id\");\n}","typeGuard":"boolean hasValidTaskId(Task t) { return t != null && t.getId() != null && !t.getId().isEmpty(); }","tryCatchPattern":"try {\n    return formService.getRenderedTaskForm(taskId);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"Task id should not be null\")) { /* reject request before engine call next time */ }\n}","preventionTips":["Save transient tasks via taskService.saveTask() before rendering forms.","Null-check task.getId() when a Task object may be unsaved.","Never pass a nullable variable straight into the form API.","Validate request parameters at the API boundary."],"tags":["null-argument","task","forms","flowable"],"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"}