{"record":{"id":"424645d0f002058c","repo":"Activiti/Activiti","slug":"cannot-combine-onlytimers-with-onlymessages-in","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":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/DeadLetterJobQueryImpl.java","lineNumber":103,"sourceCode":"        return this;\n    }\n\n    public DeadLetterJobQueryImpl executionId(String executionId) {\n        if (executionId == null) {\n            throw new ActivitiIllegalArgumentException(\"Provided execution id is null\");\n        }\n        this.executionId = executionId;\n        return this;\n    }\n\n    public DeadLetterJobQueryImpl executable() {\n        executable = true;\n        return this;\n    }\n\n    public DeadLetterJobQueryImpl timers() {\n        if (onlyMessages) {\n            throw new ActivitiIllegalArgumentException(\n                \"Cannot combine onlyTimers() with onlyMessages() in the same query\"\n            );\n        }\n        this.onlyTimers = true;\n        return this;\n    }\n\n    public DeadLetterJobQueryImpl messages() {\n        if (onlyTimers) {\n            throw new ActivitiIllegalArgumentException(\n                \"Cannot combine onlyTimers() with onlyMessages() in the same query\"\n            );\n        }\n        this.onlyMessages = true;\n        return this;\n    }\n\n    public DeadLetterJobQueryImpl duedateHigherThan(Date date) {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/DeadLetterJobQueryImpl.java#L85-L121","documentation":"DeadLetterJobQueryImpl.timers() sets an onlyTimers flag; since timer jobs and message jobs are mutually exclusive filter types, combining it with onlyMessages() is rejected. Activiti validates this eagerly in timers() to prevent contradictory SQL conditions. The same message is thrown from messages() when onlyTimers is already set.","triggerScenarios":"Chaining .timers() after .messages() (or vice versa) on the same DeadLetterJobQueryImpl instance, e.g. managementService.createDeadLetterJobQuery().messages().timers().","commonSituations":"Generic 'filter by job type' code that adds both flags from boolean parameters both set to true; copy-pasted query code; UI allowing both checkboxes to be selected and mapping them directly onto the query.","solutions":["Call only one of timers()/messages() per query instance.","Model the choice as an enum (TIMER/MESSAGE/ALL) and call the corresponding method at most once.","Build two separate queries if both types are needed and merge results in application code."],"exampleFix":"// before\nDeadLetterJobQuery q = mgmt.createDeadLetterJobQuery().messages();\nif (includeTimers) { q.timers(); } // throws\n// after\nDeadLetterJobQuery q = mgmt.createDeadLetterJobQuery();\nif (includeTimers) { q.timers(); } else if (includeMessages) { q.messages(); }","handlingStrategy":"validation","validationCode":"if (useTimers && useMessages) {\n    throw new IllegalArgumentException(\"timers and messages filters are mutually exclusive; pick one or build two queries\");\n}","typeGuard":"boolean isSingleJobTypeFilter(boolean timers, boolean messages) {\n    return !(timers && messages);\n}","tryCatchPattern":"try {\n    DeadLetterJobQuery q = mgmt.createDeadLetterJobQuery().timers();\n} catch (ActivitiIllegalArgumentException e) {\n    LOG.warn(\"Conflicting job type filters: \" + e.getMessage());\n}","preventionTips":["Use an enum (TIMER/MESSAGE/ALL) instead of two independent booleans when mapping UI/config input.","Do not chain timers()/messages() on the same query instance.","If both types are needed, run two queries and merge results."],"tags":["java","activiti","query-builder","conflicting-options"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}