{"record":{"id":"0800a2cfced35fa7","repo":"flowable/flowable-engine","slug":"cannot-combine-taskid-string-with-withouttaskid","errorCode":null,"errorMessage":"Cannot combine taskId(String) with withoutTaskId() in the same query","messagePattern":"Cannot combine taskId\\(String\\) with withoutTaskId\\(\\) in the same query","errorType":"validation","errorClass":"org.flowable.common.engine.api.FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/InternalVariableInstanceQueryImpl.java","lineNumber":72,"sourceCode":"    protected Collection<String> names;\n\n    @Override\n    public InternalVariableInstanceQuery id(String id) {\n        if (StringUtils.isEmpty(id)) {\n            throw new FlowableIllegalArgumentException(\"id is empty\");\n        }\n        this.id = id;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery taskId(String taskId) {\n        if (StringUtils.isEmpty(taskId)) {\n            throw new FlowableIllegalArgumentException(\"taskId is empty\");\n        }\n\n        if (withoutTaskId) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine taskId(String) with withoutTaskId() in the same query\");\n        }\n\n        this.taskId = taskId;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery taskIds(Collection<String> taskIds) {\n        if (taskIds == null || taskIds.isEmpty()) {\n            throw new FlowableIllegalArgumentException(\"taskIds is null or empty\");\n        }\n\n        if (withoutTaskId) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine taskIds(Collection) with withoutTaskId() in the same query\");\n        }\n        this.taskIds = taskIds;\n        return this;\n    }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/InternalVariableInstanceQueryImpl.java#L54-L90","documentation":"InternalVariableInstanceQueryImpl.taskId(String) throws FlowableIllegalArgumentException when withoutTaskId was already set on the same query. The two filters are logically contradictory — 'match this exact task' versus 'match variables with no task' — so the query builder rejects the combination at construction time rather than returning confusing results.","triggerScenarios":"Building a single InternalVariableInstanceQuery and calling taskId(\"someId\") after (or before) withoutTaskId() on the same builder instance.","commonSituations":"Query-building code that conditionally adds filters; two code paths both mutating a shared query object; copy-paste of filter blocks adding both filters.","solutions":["Remove one of the two calls — keep either taskId(...) or withoutTaskId(), not both","If both cases are needed, build two separate queries and merge results yourself","Guard the builder code so the filters are mutually exclusive branches"],"exampleFix":"// before\nquery.withoutTaskId();\nquery.taskId(taskId); // throws\n// after\nif (taskId != null) {\n    query.taskId(taskId);\n} else {\n    query.withoutTaskId();\n}","handlingStrategy":"validation","validationCode":"boolean conflicting = taskId != null && useWithoutTaskId; if (conflicting) throw new IllegalStateException(\"Choose taskId or withoutTaskId, not both\");","typeGuard":null,"tryCatchPattern":"try { buildQuery(taskId, withoutTaskId); } catch (FlowableIllegalArgumentException e) { throw new QueryConfigurationException(e.getMessage(), e); }","preventionTips":["Structure query building as if/else branches, never sequential adds of both filters","Use fresh query instances per result set instead of reusing shared builders","Centralize query construction in one helper that enforces exclusivity"],"tags":["flowable","query-builder","conflicting-filters","argument-validation"],"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"}