{"record":{"id":"eaef7524a5c22d87","repo":"SonarSource/sonarqube","slug":"field-s-is-not-sortable","errorCode":null,"errorMessage":"Field '%s' is not sortable","messagePattern":"Field '(.+?)' is not sortable","errorType":"validation","errorClass":"IllegalStateException","httpStatus":400,"severity":"error","filePath":"server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java","lineNumber":254,"sourceCode":"  }\n\n  @CheckForNull\n  public String templateKey() {\n    return templateKey;\n  }\n\n  public RuleQuery setTemplateKey(@Nullable String templateKey) {\n    this.templateKey = templateKey;\n    return this;\n  }\n\n  public String getSortField() {\n    return this.sortField;\n  }\n\n  public RuleQuery setSortField(@Nullable String field) {\n    if (field != null && !RuleIndexDefinition.SORT_FIELDS.contains(field)) {\n      throw new IllegalStateException(String.format(\"Field '%s' is not sortable\", field));\n    }\n    this.sortField = field;\n    return this;\n  }\n\n  public boolean isAscendingSort() {\n    return ascendingSort;\n  }\n\n  public RuleQuery setAscendingSort(boolean b) {\n    this.ascendingSort = b;\n    return this;\n  }\n\n  public RuleQuery setAvailableSince(@Nullable Long l) {\n    this.availableSince = l;\n    return this;\n  }","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java#L236-L272","documentation":"RuleQuery.setSortField validates that the requested sort field is one of the sortable fields defined in RuleIndexDefinition.SORT_FIELDS. Passing any other non-null field throws IllegalStateException \"Field '%s' is not sortable\".","triggerScenarios":"Calling RuleQuery.setSortField(\"myCustomField\") or a misspelled name like 'update_date' instead of an allowed value (e.g. name, updatedAt, key...) and then executing a rules search.","commonSituations":"Web API api/rules/search with an unsupported 's' (sort) parameter; frontend sending facet field names as sort keys; typos in programmatic queries.","solutions":["Use one of the documented sortable fields for api/rules/search (e.g. name, updatedAt, key).","Check RuleIndexDefinition.SORT_FIELDS for the exact allowed list.","For custom/facet fields, use facets instead of sorting, or map your field to a supported sort key."],"exampleFix":"// before\nnew RuleQuery().setSortField(\"creationDate\");\n// after\nnew RuleQuery().setSortField(\"createdAt\"); // or another entry in RuleIndexDefinition.SORT_FIELDS","handlingStrategy":"validation","validationCode":"boolean isSortable(String f) { return f == null || org.sonar.server.rule.index.RuleIndexDefinition.SORT_FIELDS.contains(f); }","typeGuard":null,"tryCatchPattern":"try { query = ruleQuery.setSortField(field); } catch (IllegalStateException e) { if (e.getMessage().endsWith(\"is not sortable\")) { query = ruleQuery.setSortField(\"name\"); } else throw e; }","preventionTips":["Only pass fields from RuleIndexDefinition.SORT_FIELDS","Whitelist sort parameters in the API layer","Fall back to a default sort when input is unknown"],"tags":["elasticsearch","validation","rules","api"],"backgroundTag":"invalid-argument-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}