{"record":{"id":"ff9b1b5ef16503f6","repo":"flowable/flowable-engine","slug":"cannot-combine-withoutsubscopeid-with-subscopeid","errorCode":null,"errorMessage":"Cannot combine withoutSubScopeId() with subScopeId(String) in the same query","messagePattern":"Cannot combine withoutSubScopeId\\(\\) with subScopeId\\(String\\) 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":170,"sourceCode":"\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)) {\n            throw new FlowableIllegalArgumentException(\"scopeType is empty\");\n        }\n        this.scopeType = scopeType;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery scopeTypes(Collection<String> scopeTypes) {\n        this.scopeTypes = scopeTypes;\n        return this;","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/InternalVariableInstanceQueryImpl.java#L152-L188","documentation":"InternalVariableInstanceQueryImpl throws this when withoutSubScopeId() is called after subScopeId(String) has already been set. The two filters contradict each other (match a specific subScopeId vs match no subScopeId), so the query refuses the combination.","triggerScenarios":"Calling query.subScopeId(\"id\") followed by query.withoutSubScopeId(); guard at InternalVariableInstanceQueryImpl.java:170 checks the subScopeId field for non-null.","commonSituations":"Adding a fallback 'exclude scoped variables' call in generic filter code without knowing the caller already set subScopeId; reusing query objects across requests.","solutions":["Call only one of subScopeId(...) or withoutSubScopeId() per query.","Clear/rebuild the query object before applying a different filtering mode.","Track which filters were applied and skip withoutSubScopeId() when subScopeId is present."],"exampleFix":"// before\nquery.subScopeId(\"subScope-1\");\nquery.withoutSubScopeId(); // throws\n\n// after\nquery.withoutSubScopeId(); // pick only one filter","handlingStrategy":"validation","validationCode":"if (subScopeId != null && wantWithoutSubScope) {\n    throw new IllegalStateException(\"Choose either subScopeId or withoutSubScopeId, not both\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track applied filters and skip withoutSubScopeId() when subScopeId is set.","Use if/else instead of sequential optional calls.","Create a new query when switching filter mode."],"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"}