flowable/flowable-engine · error · FlowableIllegalArgumentException

Cannot use taskId together with excludeTaskVariables

Error message

Cannot use taskId together with excludeTaskVariables

What it means

excludeTaskRelated is a flag that excludes variables directly related to a task. Setting it together with a taskId filter is contradictory — you cannot both target a specific task's variables and exclude task-related ones — so Flowable throws FlowableIllegalArgumentException at query-build time.

Solutions

  1. Remove excludeTaskVariables() from the query that uses taskId()
  2. Build a separate query without the exclusion flag for task-scoped lookups
  3. If the goal is non-task variables, drop the taskId filter entirely

Example fix

// before
query.excludeTaskVariables().taskId(taskId);
// after
query.taskId(taskId);
Defensive patterns

Strategy: validation

Validate before calling

if (excludeTaskRelated && taskId != null) {
    throw new IllegalArgumentException("excludeTaskVariables cannot be combined with taskId");
}

Type guard

boolean isTaskScopedQuery(VariableInstanceQuery q) { return q != null; } // enforce flag exclusivity at call site

Try / catch

try {
    query.taskId(taskId);
} catch (FlowableIllegalArgumentException e) {
    if (e.getMessage().contains("excludeTaskVariables")) {
        query = createBaseQuery().taskId(taskId);
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling variableInstanceQuery.excludeTaskVariables() (which sets excludeTaskRelated) and then taskId(id), or taskId first then the exclusion flag.

Common situations: Copy-pasted query configuration where the exclusion flag was left from a process/execution-scoped query and then a task filter was added.

Related errors


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

Appendix: source

Thrown at modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/VariableInstanceQueryImpl.java:124

        if (excludeLocalVariables) {
            throw new FlowableIllegalArgumentException("Cannot use executionIds together with excludeLocalVariables");
        }
        this.executionIds = executionIds;
        return this;
    }

    public VariableInstanceQuery activityInstanceId(String activityInstanceId) {
        this.activityInstanceId = activityInstanceId;
        return this;
    }

    @Override
    public VariableInstanceQuery taskId(String taskId) {
        if (taskId == null) {
            throw new FlowableIllegalArgumentException("taskId is null");
        }
        if (excludeTaskRelated) {
            throw new FlowableIllegalArgumentException("Cannot use taskId together with excludeTaskVariables");
        }
        if (excludeLocalVariables) {
            throw new FlowableIllegalArgumentException("Cannot use taskIds together with excludeLocalVariables");
        }
        this.taskId = taskId;
        return this;
    }

    @Override
    public VariableInstanceQueryImpl taskIds(Set<String> taskIds) {
        if (taskIds == null) {
            throw new FlowableIllegalArgumentException("taskIds is null");
        }
        if (taskIds.isEmpty()) {
            throw new FlowableIllegalArgumentException("Set of taskIds is empty");
        }
        if (excludeTaskRelated) {
            throw new FlowableIllegalArgumentException("Cannot use taskIds together with excludeTaskVariables");

View on GitHub (pinned to d6d39ce1c6)