SonarSource/sonarqube · error · IllegalStateException

Field ' ' is not sortable

Error message

Field '%s' is not sortable

What it means

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".

Solutions

  1. Use one of the documented sortable fields for api/rules/search (e.g. name, updatedAt, key).
  2. Check RuleIndexDefinition.SORT_FIELDS for the exact allowed list.
  3. For custom/facet fields, use facets instead of sorting, or map your field to a supported sort key.

Example fix

// before
new RuleQuery().setSortField("creationDate");
// after
new RuleQuery().setSortField("createdAt"); // or another entry in RuleIndexDefinition.SORT_FIELDS
Defensive patterns

Strategy: validation

Validate before calling

boolean isSortable(String f) { return f == null || org.sonar.server.rule.index.RuleIndexDefinition.SORT_FIELDS.contains(f); }

Try / catch

try { query = ruleQuery.setSortField(field); } catch (IllegalStateException e) { if (e.getMessage().endsWith("is not sortable")) { query = ruleQuery.setSortField("name"); } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Web API api/rules/search with an unsupported 's' (sort) parameter; frontend sending facet field names as sort keys; typos in programmatic queries.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/eaef7524a5c22d87. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java:254

  }

  @CheckForNull
  public String templateKey() {
    return templateKey;
  }

  public RuleQuery setTemplateKey(@Nullable String templateKey) {
    this.templateKey = templateKey;
    return this;
  }

  public String getSortField() {
    return this.sortField;
  }

  public RuleQuery setSortField(@Nullable String field) {
    if (field != null && !RuleIndexDefinition.SORT_FIELDS.contains(field)) {
      throw new IllegalStateException(String.format("Field '%s' is not sortable", field));
    }
    this.sortField = field;
    return this;
  }

  public boolean isAscendingSort() {
    return ascendingSort;
  }

  public RuleQuery setAscendingSort(boolean b) {
    this.ascendingSort = b;
    return this;
  }

  public RuleQuery setAvailableSince(@Nullable Long l) {
    this.availableSince = l;
    return this;
  }

View on GitHub (pinned to 184c821202)