{"record":{"id":"5fa01942cce80521","repo":"flowable/flowable-engine","slug":"invalid-query-call-asc-or-desc-after-using-or-5fa019","errorCode":null,"errorMessage":"Invalid query: call asc() or desc() after using orderByXX()","messagePattern":"Invalid query: call asc\\(\\) or desc\\(\\) after using orderByXX\\(\\)","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/AbstractQuery.java","lineNumber":121,"sourceCode":"    @Override\n    public T desc() {\n        return direction(Direction.DESCENDING);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public T direction(Direction direction) {\n        if (orderProperty == null) {\n            throw new ActivitiIllegalArgumentException(\"You should call any of the orderBy methods first before specifying a direction\");\n        }\n        addOrder(orderProperty.getName(), direction.getName(), nullHandlingOnOrder);\n        orderProperty = null;\n        nullHandlingOnOrder = null;\n        return (T) this;\n    }\n\n    protected void checkQueryOk() {\n        if (orderProperty != null) {\n            throw new ActivitiIllegalArgumentException(\"Invalid query: call asc() or desc() after using orderByXX()\");\n        }\n    }\n\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public U singleResult() {\n        this.resultType = ResultType.SINGLE_RESULT;\n        if (commandExecutor != null) {\n            return (U) commandExecutor.execute(this);\n        }\n        return executeSingleResult(Context.getCommandContext());\n    }\n\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public List<U> list() {\n        this.resultType = ResultType.LIST;\n        if (commandExecutor != null) {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/AbstractQuery.java#L103-L139","documentation":"AbstractQuery.checkQueryOk() is invoked before executing a query (e.g. singleResult(), list()). It throws ActivitiIllegalArgumentException if orderProperty != null, meaning the caller used orderByXX() but never followed it with asc() or desc(). A sort property without a direction leaves the order-by clause incomplete.","triggerScenarios":"taskQuery.orderByTaskCreateTime().list() — orderBy called but asc()/desc() omitted before list()/singleResult()/count().","commonSituations":"Refactors dropping the .asc()/.desc() suffix; conditional building where the direction branch was skipped; developers assuming a default direction exists (it does not).","solutions":["Terminate every orderByXX() chain with .asc() or .desc().","If direction is dynamic, ensure both branches call it: q.orderByX().(dir ? asc() : desc()).","Only skip ordering entirely — do not call orderBy at all — if no sort is desired."],"exampleFix":"// before\nList<Task> tasks = taskService.createTaskQuery().orderByTaskPriority().list(); // throws\n// after\nList<Task> tasks = taskService.createTaskQuery().orderByTaskPriority().desc().list();","handlingStrategy":"validation","validationCode":"// rule: every orderBy must be followed by asc/desc before list()\nquery = sortCol != null ? query.orderBy(sortCol).(asc ? query.asc() : query.desc()) : query;","typeGuard":null,"tryCatchPattern":"try { return query.list(); } catch (ActivitiIllegalArgumentException e) { if (e.getMessage().contains(\"asc() or desc()\")) { return query.asc().list(); } throw e; }","preventionTips":["Treat orderByXX() as requiring a terminating asc()/desc() — never end a chain on orderBy","Pick a project-wide default direction helper, e.g. QueryUtils.sorted(query, col, dir)","Add unit tests that execute every query builder path"],"tags":["query","sorting","api-usage-order","illegal-argument"],"backgroundTag":"invalid-api-call-order","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"}