{"record":{"id":"d8d16f52d35a4175","repo":"flowable/flowable-engine","slug":"cannot-combine-subscopeid-string-with-withoutsubs","errorCode":null,"errorMessage":"Cannot combine subScopeId(String) with withoutSubScopeId() in the same query","messagePattern":"Cannot combine subScopeId\\(String\\) 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":150,"sourceCode":"        }\n        this.scopeId = scopeId;\n        return this;\n    }\n\n    @Override\n    public InternalVariableInstanceQuery scopeIds(Collection<String> scopeIds) {\n        this.scopeIds = scopeIds;\n        return this;\n    }\n\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() {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/InternalVariableInstanceQueryImpl.java#L132-L168","documentation":"Flowable's InternalVariableInstanceQueryImpl throws this when subScopeId(String) is called after withoutSubScopeId() has already been set. These two filters are logically contradictory: one targets variables under a specific sub-scope, the other targets variables with no sub-scope, so no query could satisfy both.","triggerScenarios":"Calling query.withoutSubScopeId() followed by query.subScopeId(\"someId\") on the same InternalVariableInstanceQuery instance; the guard at InternalVariableInstanceQueryImpl.java:150 fires because the withoutSubScopeId flag is already true.","commonSituations":"Dynamically building query filters where optional criteria are added conditionally and both a 'has subScopeId' and 'has no subScopeId' branch can run for the same query object; reusing a cached/shared query instance across code paths.","solutions":["Decide which filter you need and call only one of subScopeId(...) or withoutSubScopeId() per query.","Build a fresh InternalVariableInstanceQuery instead of reusing a configured one.","Wrap conditional filter addition in if/else so the two options are mutually exclusive."],"exampleFix":"// before\nquery.withoutSubScopeId();\nquery.subScopeId(\"subScope-1\"); // throws\n\n// after\nquery.subScopeId(\"subScope-1\"); // pick only one filter","handlingStrategy":"validation","validationCode":"if (useWithoutSubScope && subScopeId != null) {\n    throw new IllegalStateException(\"Choose either subScopeId or withoutSubScopeId, not both\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Encapsulate subScope filtering in one builder method that applies exactly one of the two options.","Never reuse a configured query object across code paths.","Centralize filter addition so mutual exclusion is enforced in one place."],"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"}