flowable/flowable-engine · error · ActivitiIllegalArgumentException

taskId is null

Error message

taskId is null

What it means

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.

Solutions

  1. Assert the taskId is non-null before calling taskService.getVariable/getVariableLocal.
  2. Fix the upstream code path that produced a null id (uninitialized field, unbound request parameter).
  3. Return a 400-style validation error to callers instead of letting the engine throw.
  4. For optional task lookups, first check task existence and skip the variable fetch when absent.

Example fix

// before
Object value = taskService.getVariable(taskId, "status");
// after
if (taskId == null) {
    throw new IllegalArgumentException("taskId is required");
}
Object value = taskService.getVariable(taskId, "status");
Defensive patterns

Strategy: validation

Validate before calling

if (taskId == null) throw new IllegalArgumentException("taskId must not be null");

Try / catch

try {
    return taskService.getVariable(taskId, name);
} catch (ActivitiIllegalArgumentException e) {
    if (e.getMessage().equals("taskId is null")) return null;
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/c1b231d0288a1a8e. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetTaskVariableCmd.java:45

 * @author Joram Barrez
 */
public class GetTaskVariableCmd implements Command<Object>, Serializable {

    private static final long serialVersionUID = 1L;
    protected String taskId;
    protected String variableName;
    protected boolean isLocal;

    public GetTaskVariableCmd(String taskId, String variableName, boolean isLocal) {
        this.taskId = taskId;
        this.variableName = variableName;
        this.isLocal = isLocal;
    }

    @Override
    public Object execute(CommandContext commandContext) {
        if (taskId == null) {
            throw new ActivitiIllegalArgumentException("taskId is null");
        }
        if (variableName == null) {
            throw new ActivitiIllegalArgumentException("variableName is null");
        }

        TaskEntity task = commandContext
                .getTaskEntityManager()
                .findTaskById(taskId);

        if (task == null) {
            throw new ActivitiObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
        }

        Object value;

        if (isLocal) {
            value = task.getVariableLocal(variableName, false);
        } else {

View on GitHub (pinned to d6d39ce1c6)