{"record":{"id":"0303126ddbd65de5","repo":"flowable/flowable-engine","slug":"invalid-usage-cannot-use-deployed-and-notdeploy","errorCode":null,"errorMessage":"Invalid usage: cannot use deployed() and notDeployed() in the same query","messagePattern":"Invalid usage: cannot use deployed\\(\\) and notDeployed\\(\\) in the same query","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/ModelQueryImpl.java","lineNumber":149,"sourceCode":"    @Override\n    public ModelQuery latestVersion() {\n        this.latest = true;\n        return this;\n    }\n\n    @Override\n    public ModelQuery deploymentId(String deploymentId) {\n        if (deploymentId == null) {\n            throw new FlowableIllegalArgumentException(\"DeploymentId is null\");\n        }\n        this.deploymentId = deploymentId;\n        return this;\n    }\n\n    @Override\n    public ModelQuery notDeployed() {\n        if (deployed) {\n            throw new FlowableIllegalArgumentException(\"Invalid usage: cannot use deployed() and notDeployed() in the same query\");\n        }\n        this.notDeployed = true;\n        return this;\n    }\n\n    @Override\n    public ModelQuery deployed() {\n        if (notDeployed) {\n            throw new FlowableIllegalArgumentException(\"Invalid usage: cannot use deployed() and notDeployed() in the same query\");\n        }\n        this.deployed = true;\n        return this;\n    }\n\n    @Override\n    public ModelQuery modelTenantId(String tenantId) {\n        if (tenantId == null) {\n            throw new FlowableIllegalArgumentException(\"Model tenant id is null\");","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/ModelQueryImpl.java#L131-L167","documentation":"ModelQueryImpl.notDeployed() marks the query as filtering for models not yet deployed, but deployed() and notDeployed() are mutually exclusive filters. If deployed() was already called on the same query, notDeployed() throws FlowableIllegalArgumentException to prevent a contradictory WHERE condition. This is a fail-fast guard against an impossible query.","triggerScenarios":"Calling both deployed() and notDeployed() on the same ModelQuery instance, e.g. building the filter dynamically from flags where both booleans end up true (user selected both options in a UI, or two code paths each add one filter).","commonSituations":"Dynamic query builders in REST/admin UIs mapping checkbox states straight to query calls; refactored code where a shared query object is reused and one method already applied deployed(); copying example code that had deployed() and adding notDeployed().","solutions":["Use only one of deployed() or notDeployed() per query instance.","If the choice is dynamic, branch: if (onlyDeployed) q.deployed(); else if (onlyNotDeployed) q.notDeployed();","Mutually exclude the flags at the input/validation layer so both can never be true.","Create a fresh ModelQuery instead of reusing one that already has a deployment filter applied."],"exampleFix":"// before\nModelQuery query = repositoryService.createModelQuery()\n    .deployed()\n    .notDeployed(); // contradiction\n\n// after\nModelQuery query = repositoryService.createModelQuery();\nif (deployedOnly) {\n    query.deployed();\n} else {\n    query.notDeployed();\n}","handlingStrategy":"validation","validationCode":"if (onlyDeployed && onlyNotDeployed) {\n    throw new IllegalArgumentException(\"Choose either deployed or notDeployed filter, not both\");\n}\nModelQuery q = repositoryService.createModelQuery();\nif (onlyDeployed) q.deployed(); else if (onlyNotDeployed) q.notDeployed();","typeGuard":null,"tryCatchPattern":"try {\n    return queryBuilder.applyDeploymentFilter(flags).list();\n} catch (FlowableIllegalArgumentException e) {\n    log.warn(\"Conflicting deployment filters: {}\", e.getMessage());\n    throw new BadRequestException(\"deployed and notDeployed cannot be combined\");\n}","preventionTips":["Enforce mutual exclusivity of deployed/notDeployed in UI or REST validation.","Build queries with at most one deployment-state filter.","Avoid reusing a single ModelQuery across code paths that each add filters.","Document the filter flags so both cannot default to true."],"tags":["flowable","query-builder","mutually-exclusive","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-14T11:17:12.474Z"}