{"record":{"id":"59f9557f5b21a181","repo":"flowable/flowable-engine","slug":"cannot-combine-subscopeids-with-withoutsubscopeid","errorCode":null,"errorMessage":"Cannot combine subScopeIds with withoutSubScopeId in the same query","messagePattern":"Cannot combine subScopeIds with withoutSubScopeId in the same query","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/InternalVariableInstanceQueryImpl.java","lineNumber":160,"sourceCode":"\n    @Override\n    public InternalVariableInstanceQuery subScopeId(String subScopeId) {\n        if (StringUtils.isEmpty(subScopeId)) {\n            throw new FlowableIllegalArgumentException(\"subScopeId is empty\");\n        }\n\n        if (withoutSubScopeId) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine subScopeId(String) with withoutSubScopeId() in the same query\");\n        }\n\n        this.subScopeId = subScopeId;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery subScopeIds(Collection<String> subScopeIds) {\n        if (withoutSubScopeId) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine subScopeIds with withoutSubScopeId in the same query\");\n        }\n\n        this.subScopeIds = subScopeIds;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery withoutSubScopeId() {\n        if (subScopeId != null) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine withoutSubScopeId() with subScopeId(String) in the same query\");\n        }\n        this.withoutSubScopeId = true;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery scopeType(String scopeType) {\n        if (StringUtils.isEmpty(scopeType)) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/InternalVariableInstanceQueryImpl.java#L142-L178","documentation":"InternalVariableInstanceQueryImpl throws this when subScopeIds(Collection) is called after withoutSubScopeId() was already set. Filtering for variables under a set of subScopeIds conflicts with filtering for variables that have no subScopeId at all, so the combination is rejected.","triggerScenarios":"Calling query.withoutSubScopeId() and then query.subScopeIds(Arrays.asList(\"a\",\"b\")); guard at InternalVariableInstanceQueryImpl.java:160 checks the withoutSubScopeId flag.","commonSituations":"Programmatic query builders collecting a list of scope IDs while another code path has already flagged 'exclude any subScopeId'; refactoring code from withoutSubScopeId() to a list filter without resetting the query.","solutions":["Use either withoutSubScopeId() or subScopeIds(...) — never both on one query.","If the collection may be empty and you intended 'no subScopeId', call withoutSubScopeId() only.","Create a new query instance when switching filtering strategy."],"exampleFix":"// before\nquery.withoutSubScopeId();\nquery.subScopeIds(ids); // throws\n\n// after\nif (ids.isEmpty()) {\n    query.withoutSubScopeId();\n} else {\n    query.subScopeIds(ids);\n}","handlingStrategy":"validation","validationCode":"if (useWithoutSubScope && subScopeIds != null && !subScopeIds.isEmpty()) {\n    throw new IllegalStateException(\"Choose either subScopeIds or withoutSubScopeId, not both\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Branch on collection emptiness: empty list -> withoutSubScopeId(), otherwise subScopeIds(...).","Build queries fresh for each request.","Document the mutual exclusion in your query-builder API."],"tags":["query","validation","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"}