{"record":{"id":"939861b5b2cf7a0b","repo":"flowable/flowable-engine","slug":"cannot-combine-onlytimers-with-onlymessages-in-939861","errorCode":null,"errorMessage":"Cannot combine onlyTimers() with onlyMessages() in the same query","messagePattern":"Cannot combine onlyTimers\\(\\) with onlyMessages\\(\\) in the same query","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-job-service/src/main/java/org/flowable/job/service/impl/JobQueryImpl.java","lineNumber":412,"sourceCode":"    }\n\n    @Override\n    public JobQuery handlerTypes(Collection<String> handlerTypes) {\n        if (handlerTypes == null) {\n            throw new FlowableIllegalArgumentException(\"Provided handlerTypes are null\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.handlerTypes = handlerTypes;\n        } else {\n            this.handlerTypes = handlerTypes;\n        }\n        return this;\n    }\n\n    @Override\n    public JobQuery timers() {\n        if (onlyMessages) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine onlyTimers() with onlyMessages() in the same query\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.onlyTimers = true;\n        } else {\n            this.onlyTimers = true;\n        }\n        return this;\n    }\n\n    @Override\n    public JobQuery messages() {\n        if (onlyTimers) {\n            throw new FlowableIllegalArgumentException(\"Cannot combine onlyTimers() with onlyMessages() in the same query\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.onlyMessages = true;\n        } else {\n            this.onlyMessages = true;","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-job-service/src/main/java/org/flowable/job/service/impl/JobQueryImpl.java#L394-L430","documentation":"FlowableIllegalArgumentException thrown by JobQueryImpl.timers() when onlyMessages is already set on the query. The onlyTimers and onlyMessages filters are mutually exclusive: a job is either a timer job or a message/async job, so combining both would yield a logically empty query. Flowable rejects the combination at query-build time.","triggerScenarios":"Calling jobQuery.timers() after jobQuery.messages() on the same query instance, or building a query with conditionally-added filters where both flags end up set (also applies inside an or() block).","commonSituations":"Dynamic query builders that add filters based on user-selected checkboxes where 'timers' and 'messages' were both selected; copy-pasted query code accumulating both flags.","solutions":["Call only one of timers() or messages() per query; drop the conflicting call.","Track which filter was set and use onlyMessages()/onlyTimers() mutually exclusively in your builder.","If both job kinds are needed, run two separate queries and merge results instead of one query with both flags.","To remove a previously set filter, build a fresh JobQueryImpl rather than flipping flags."],"exampleFix":"// before\nif (filterTimers) query.timers();\nif (filterMessages) query.messages(); // throws when both true\n\n// after\nif (filterTimers && filterMessages) {\n    // run two queries, or treat as 'no filter'\n} else if (filterTimers) {\n    query.timers();\n} else if (filterMessages) {\n    query.messages();\n}","handlingStrategy":"validation","validationCode":"if (filterTimers && filterMessages) {\n    throw new IllegalArgumentException(\"timers and messages filters are mutually exclusive; run separate queries\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    query.timers();\n} catch (org.flowable.common.engine.api.FlowableIllegalArgumentException e) {\n    // onlyMessages already set: rebuild the query with only one kind filter\n    query = jobService.createJobQuery();\n}","preventionTips":["Model timers/messages as a single enum choice (TIMERS | MESSAGES | ALL) instead of two booleans.","Track which kind-filter was applied on the query instance.","Write unit tests for your query builder covering both-flags-selected input."],"tags":["mutually-exclusive","query","validation","flowable"],"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"}