{"record":{"id":"716fb03f49cae40a","repo":"flowable/flowable-engine","slug":"the-query-is-already-in-an-or-statement-716fb0","errorCode":null,"errorMessage":"the query is already in an or statement","messagePattern":"the query is already in an or statement","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-eventsubscription-service/src/main/java/org/flowable/eventsubscription/service/impl/EventSubscriptionQueryImpl.java","lineNumber":474,"sourceCode":"        }\n\n        return this;\n    }\n\n    @Override\n    public EventSubscriptionQueryImpl withoutConfiguration() {\n        if (inOrStatement) {\n            this.currentOrQueryObject.withoutConfiguration = true;\n        } else {\n            this.withoutConfiguration = true;\n        }\n        return this;\n    }\n\n    @Override\n    public EventSubscriptionQuery or() {\n        if (inOrStatement) {\n            throw new FlowableException(\"the query is already in an or statement\");\n        }\n\n        inOrStatement = true;\n        currentOrQueryObject = new EventSubscriptionQueryImpl();\n        orQueryObjects.add(currentOrQueryObject);\n        return this;\n    }\n\n    @Override\n    public EventSubscriptionQuery endOr() {\n        if (!inOrStatement) {\n            throw new FlowableException(\"endOr() can only be called after calling or()\");\n        }\n\n        inOrStatement = false;\n        currentOrQueryObject = null;\n        return this;\n    }","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-eventsubscription-service/src/main/java/org/flowable/eventsubscription/service/impl/EventSubscriptionQueryImpl.java#L456-L492","documentation":"EventSubscriptionQuery.or() opens an OR block in the fluent query. Flowable throws FlowableException (not an argument error) if or() is invoked while the query is already inside an OR statement, because nested OR groups are unsupported by this query implementation. This is an API-state rule, not a data problem.","triggerScenarios":"Calling query.or() twice without an intervening endOr(), e.g. building filters in a loop that calls or() per condition, or duplicating query-building code paths that each open an OR block.","commonSituations":"Dynamic filter builders where the same or() call is executed for each incoming filter criterion; copy-pasted query assembly in two branches both calling or().","solutions":["Call or() once, add all OR-joined predicates, then call endOr() before opening another block","Guard the or() call with a boolean flag tracking whether the OR block is open","Restructure the loop to add criteria inside a single or()...endOr() span"],"exampleFix":"// before\nfor (Filter f : filters) {\n    query.or().eventSubscriptionType(f.getType());\n}\n\n// after\nquery.or();\nfor (Filter f : filters) {\n    query.eventSubscriptionType(f.getType());\n}\nquery.endOr();","handlingStrategy":"try-catch","validationCode":"if (query instanceof EventSubscriptionQueryImpl && ((EventSubscriptionQueryImpl) query).inOrStatement) {\n    throw new IllegalStateException(\"or() called while already in OR statement\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    query.or();\n} catch (FlowableException e) {\n    log.error(\"Nested or() not supported: {}\", e.getMessage());\n    throw e;\n}","preventionTips":["Call or() exactly once per OR group, followed by endOr()","Never call or() inside per-criterion loops","Encapsulate OR grouping in a single helper method"],"tags":["flowable","query","or-statement","api-misuse"],"backgroundTag":"invalid-state-transition","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"}