SonarSource/sonarqube · error · IllegalArgumentException

Bad sort field:

Error message

Bad sort field: 

What it means

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.

Source

Thrown at server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java:709

    public Builder createdAfter(@Nullable Date d) {
      this.createdAfter(d, true);
      return this;
    }

    public Builder createdAfter(@Nullable Date d, boolean inclusive) {
      this.createdAfter = d == null ? null : new PeriodStart(new Date(d.getTime()), inclusive);
      return this;
    }

    public Builder createdBefore(@Nullable Date d) {
      this.createdBefore = d == null ? null : new Date(d.getTime());
      return this;
    }

    public Builder sort(@Nullable String s) {
      if (s != null && !SORTS.contains(s)) {
        throw new IllegalArgumentException("Bad sort field: " + s);
      }
      this.sort = s;
      return this;
    }

    public Builder asc(@Nullable Boolean asc) {
      this.asc = asc;
      return this;
    }

    public IssueQuery build() {
      return new IssueQuery(this);
    }

    public Builder facetMode(String facetMode) {
      this.facetMode = facetMode;
      return this;
    }

View on GitHub (pinned to 184c821202)

Solutions

  1. 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.).
  2. Verify exact case and spelling of the sort value.
  3. If migrating from an older version, update the client to the sort values accepted by the current server.
  4. Drop the sort parameter to fall back to the default ordering.

Example fix

// before
GET /api/issues/search?s=severity
// after
GET /api/issues/search?s=SEVERITY
Defensive patterns

Strategy: validation

Validate before calling

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
if (sort != null && !allowed.contains(sort)) throw new IllegalArgumentException(sort);

Try / catch

try { issuesApi.search(s(sort)); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Bad sort field")) { /* fall back to default sort */ } }

Prevention

When it happens

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

Common situations: 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).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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