{"record":{"id":"e07b5a682c1a928a","repo":"SonarSource/sonarqube","slug":"bad-sort-field","errorCode":null,"errorMessage":"Bad sort field: ","messagePattern":"Bad sort field: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java","lineNumber":709,"sourceCode":"\n    public Builder createdAfter(@Nullable Date d) {\n      this.createdAfter(d, true);\n      return this;\n    }\n\n    public Builder createdAfter(@Nullable Date d, boolean inclusive) {\n      this.createdAfter = d == null ? null : new PeriodStart(new Date(d.getTime()), inclusive);\n      return this;\n    }\n\n    public Builder createdBefore(@Nullable Date d) {\n      this.createdBefore = d == null ? null : new Date(d.getTime());\n      return this;\n    }\n\n    public Builder sort(@Nullable String s) {\n      if (s != null && !SORTS.contains(s)) {\n        throw new IllegalArgumentException(\"Bad sort field: \" + s);\n      }\n      this.sort = s;\n      return this;\n    }\n\n    public Builder asc(@Nullable Boolean asc) {\n      this.asc = asc;\n      return this;\n    }\n\n    public IssueQuery build() {\n      return new IssueQuery(this);\n    }\n\n    public Builder facetMode(String facetMode) {\n      this.facetMode = facetMode;\n      return this;\n    }","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java#L691-L727","documentation":"IssueQuery.Builder.sort validates the sort field against the known SORTS set. Passing any string outside that whitelist throws IllegalArgumentException(\"Bad sort field: \" + s). The thrown message includes the offending value, though the catalogued template is just the prefix.","triggerScenarios":"Calling api/issues/search with a 's' (sort) parameter not in the accepted list (e.g. 'severity', 'DATE', or a typo like 'updater' instead of 'updateDate').","commonSituations":"Hand-written query strings or dashboards with an outdated sort field; API changes between SonarQube versions renaming/removing sort values; case-sensitivity mistakes (SORTS is exact-match).","solutions":["Use one of the documented sort values exactly as listed (check the api/issues/search 's' parameter docs, e.g. FILE_LINE, ISSUE_STATUS, SEVERITY, UPDATE_DATE, etc.).","Verify exact case and spelling of the sort value.","If migrating from an older version, update the client to the sort values accepted by the current server.","Drop the sort parameter to fall back to the default ordering."],"exampleFix":"// before\nGET /api/issues/search?s=severity\n// after\nGET /api/issues/search?s=SEVERITY","handlingStrategy":"validation","validationCode":"Set<String> allowed = Set.of(\"FILE_LINE\",\"ISSUE_STATUS\",\"SEVERITY\",\"UPDATE_DATE\",\"CREATION_DATE\",\"UPDATE_DATE_ASC\",\"...\"); // use values from the api/issues/search docs\nif (sort != null && !allowed.contains(sort)) throw new IllegalArgumentException(sort);","typeGuard":null,"tryCatchPattern":"try { issuesApi.search(s(sort)); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Bad sort field\")) { /* fall back to default sort */ } }","preventionTips":["Copy sort values from the current server's WS documentation","Centralize sort constants in one enum in client code","Check release notes when upgrading SonarQube versions"],"tags":["issues-search","sorting","validation","java"],"backgroundTag":"invalid-enum-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}