{"record":{"id":"f93f1113ed6ecb1e","repo":"flowable/flowable-engine","slug":"cannot-use-taskid-together-with-excludetaskvariabl-f93f11","errorCode":null,"errorMessage":"Cannot use taskId together with excludeTaskVariables","messagePattern":"Cannot use taskId together with excludeTaskVariables","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricVariableInstanceQueryImpl.java","lineNumber":109,"sourceCode":"        if (executionIds.isEmpty()) {\n            throw new ActivitiIllegalArgumentException(\"Set of executionIds is empty\");\n        }\n        this.executionIds = executionIds;\n        return this;\n    }\n\n    public HistoricVariableInstanceQuery activityInstanceId(String activityInstanceId) {\n        this.activityInstanceId = activityInstanceId;\n        return this;\n    }\n\n    @Override\n    public HistoricVariableInstanceQuery taskId(String taskId) {\n        if (taskId == null) {\n            throw new ActivitiIllegalArgumentException(\"taskId is null\");\n        }\n        if (excludeTaskRelated) {\n            throw new ActivitiIllegalArgumentException(\"Cannot use taskId together with excludeTaskVariables\");\n        }\n        this.taskId = taskId;\n        return this;\n    }\n\n    @Override\n    public HistoricVariableInstanceQueryImpl taskIds(Set<String> taskIds) {\n        if (taskIds == null) {\n            throw new ActivitiIllegalArgumentException(\"taskIds is null\");\n        }\n        if (taskIds.isEmpty()) {\n            throw new ActivitiIllegalArgumentException(\"Set of taskIds is empty\");\n        }\n        if (excludeTaskRelated) {\n            throw new ActivitiIllegalArgumentException(\"Cannot use taskIds together with excludeTaskVariables\");\n        }\n        this.taskIds = taskIds;\n        return this;","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/HistoricVariableInstanceQueryImpl.java#L91-L127","documentation":"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.","triggerScenarios":"Calling historyService.createHistoricVariableInstanceQuery().excludeTaskVariables().taskId(\"123\") — i.e. excludeTaskVariables() before taskId() — throws immediately.","commonSituations":"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.","solutions":["Remove the excludeTaskVariables() call if you actually want variables of the given task.","Remove or make the taskId() call conditional when you intend to exclude task variables.","Build two separate query objects instead of reusing one for both filter modes."],"exampleFix":"// before\nquery.excludeTaskVariables().taskId(taskId);\n// after\nquery.taskId(taskId); // drop excludeTaskVariables when filtering by task","handlingStrategy":"validation","validationCode":"if (useExcludeTaskVariables) {\n    query.excludeTaskVariables();\n} else if (taskId != null) {\n    query.taskId(taskId);\n}","typeGuard":null,"tryCatchPattern":"try { query.taskId(taskId); } catch (org.activiti.engine.ActivitiIllegalArgumentException e) { log.warn(\"taskId conflicts with excludeTaskVariables, dropping taskId\"); query = query.excludeTaskVariables(); }","preventionTips":["Track which mutually exclusive filters were applied in your query-builder wrapper.","Never reuse a single query object for different filter modes.","Add unit tests for each filter combination you support."],"tags":["java","activiti","query-builder","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","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"}