SonarSource/sonarqube · error · IllegalArgumentException
Cannot sort on field :
Error message
Cannot sort on field :
What it means
Raised when api/issues/search receives a 'sort' (s) value that IssuesFinderSort cannot map to a known sort processor. Only a fixed set of sort fields is supported and the request value is passed through to the issue index.
Source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssuesFinderSort.java:70
}
private static IssueProcessor getIssueProcessor(String sort) {
if (IssueQuery.SORT_BY_SEVERITY.equals(sort)) {
return new SeveritySortIssueProcessor();
}
if (IssueQuery.SORT_BY_STATUS.equals(sort)) {
return new StatusSortIssueProcessor();
}
if (IssueQuery.SORT_BY_CREATION_DATE.equals(sort)) {
return new CreationDateSortIssueProcessor();
}
if (IssueQuery.SORT_BY_UPDATE_DATE.equals(sort)) {
return new UpdateDateSortIssueProcessor();
}
if (IssueQuery.SORT_BY_CLOSE_DATE.equals(sort)) {
return new CloseDateSortIssueProcessor();
}
throw new IllegalArgumentException("Cannot sort on field : " + sort);
}
interface IssueProcessor {
Function sortFieldFunction();
Ordering sortFieldOrdering(boolean ascending);
default List<IssueDto> sort(Collection<IssueDto> issueDtos, boolean ascending) {
Ordering<IssueDto> ordering = sortFieldOrdering(ascending).onResultOf(sortFieldFunction());
return ordering.immutableSortedCopy(issueDtos);
}
}
abstract static class TextSortIssueProcessor implements IssueProcessor {
@Override
public Function sortFieldFunction() {
return (Function<IssueDto, String>) this::sortField;
}View on GitHub (pinned to 184c821202)
Solutions
- Use a supported sort value (e.g. SEVERITY, CREATION_DATE, UPDATE_DATE, FILE_LINE, CLOSE_DATE)
- Check the api/issues/search documentation for the exact allowed sort values on your server version
- Remove the sort parameter if default ordering is acceptable
Example fix
// before curl '.../api/issues/search?projectKeys=p&s=created' // after curl '.../api/issues/search?projectKeys=p&s=CREATION_DATE'
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED_SORTS = ['FILE_LINE','SEVERITY','UPDATE_DATE','CLOSE_DATE','CREATION_DATE'];
if (sort && !ALLOWED_SORTS.includes(sort)) throw new Error(`unsupported sort: ${sort}`); Try / catch
try { await get('/api/issues/search', {s: sort}); } catch (e) { if (e.status === 400 && e.message.startsWith('Cannot sort on field')) { /* fall back to default sort */ } else throw e; } Prevention
- Whitelist sort values against your server's docs
- Centralize sort constants in shared client code
- Test sort params against the target SonarQube version
When it happens
Trigger: Calling GET api/issues/search with s=<unsupported field>, e.g. s=created (instead of CREATION_DATE) or a custom field name; sort values differ from what Elasticsearch indexing supports for issues.
Common situations: Guessing sort field names instead of using documented values (FILE_LINE, SEVERITY, UPDATE_DATE, CLOSE_DATE, etc.); copy-pasting sort values from other SonarQube endpoints like rules or components; older servers lacking newer sort fields.
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
- Missing parameter : 'comment'
- Issue with key '%s' does not exist
- Component of type '%s' is not supported
- Parameters 'severity' and 'impact' cannot be used at the sam
- One of the parameters 'severity' or 'impact' must be provide
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/5d212d03c70378a9.
Report an issue: GitHub.