flowable/flowable-engine · error · ActivitiIllegalArgumentException

Cannot use taskId together with excludeTaskVariables

Error message

Cannot use taskId together with excludeTaskVariables

What it means

HistoricVariableInstanceQueryImpl.taskId() refuses to set a taskId when excludeTaskVariables() was already called on this query (the excludeTaskRelated flag is set). The two are mutually exclusive: one filters variables belonging to a specific task, the other excludes task-related variables entirely, and combining them yields an ill-defined query. The engine fails fast with ActivitiIllegalArgumentException at query-construction time.

Solutions

  1. Remove the excludeTaskVariables() call if you actually want variables of the given task.
  2. Remove or make the taskId() call conditional when you intend to exclude task variables.
  3. Build two separate query objects instead of reusing one for both filter modes.

Example fix

// before
query.excludeTaskVariables().taskId(taskId);
// after
query.taskId(taskId); // drop excludeTaskVariables when filtering by task
Defensive patterns

Strategy: validation

Validate before calling

if (useExcludeTaskVariables) {
    query.excludeTaskVariables();
} else if (taskId != null) {
    query.taskId(taskId);
}

Try / catch

try { query.taskId(taskId); } catch (org.activiti.engine.ActivitiIllegalArgumentException e) { log.warn("taskId conflicts with excludeTaskVariables, dropping taskId"); query = query.excludeTaskVariables(); }

Prevention

When it happens

Trigger: Calling historyService.createHistoricVariableInstanceQuery().excludeTaskVariables().taskId("123") — i.e. excludeTaskVariables() before taskId() — throws immediately.

Common situations: Builders that conditionally chain filters (e.g. adding excludeTaskVariables for some requests and taskId for others) on the same query object; copy-paste of a query-building snippet that already contained excludeTaskVariables(); reusing a shared query object across call paths.

Related errors


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

Appendix: source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricVariableInstanceQueryImpl.java:109

        if (executionIds.isEmpty()) {
            throw new ActivitiIllegalArgumentException("Set of executionIds is empty");
        }
        this.executionIds = executionIds;
        return this;
    }

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

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

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

View on GitHub (pinned to d6d39ce1c6)