SonarSource/sonarqube · error · IllegalArgumentException

Languages should be set either by using 'languages = java' o

Error message

Languages should be set either by using 'languages = java' or 'languages IN (java, js)'

What it means

SonarQube's project measures/search WS only accepts a languages criterion with the '=' or 'IN' operator and at least one value. processLanguages throws this IllegalArgumentException for any other operator (e.g. '!=', '>', missing operator) or when the criterion has no values.

Source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java:99

  private static void processIsFavorite(Criterion criterion) {
    checkArgument(criterion.getOperator() == null && criterion.getValue() == null, "Filter on favorites should be declared without an operator nor a value");
  }

  private static void processLanguages(Criterion criterion, ProjectMeasuresQuery query) {
    checkOperator(criterion);
    Operator operator = criterion.getOperator();
    String value = criterion.getValue();
    List<String> values = criterion.getValues();
    if (value != null && EQ.equals(operator)) {
      query.setLanguages(singleton(value));
      return;
    }
    if (!values.isEmpty() && IN.equals(operator)) {
      query.setLanguages(new HashSet<>(values));
      return;
    }
    throw new IllegalArgumentException("Languages should be set either by using 'languages = java' or 'languages IN (java, js)'");
  }

  private static void processTags(Criterion criterion, ProjectMeasuresQuery query) {
    checkOperator(criterion);
    Operator operator = criterion.getOperator();
    String value = criterion.getValue();
    List<String> values = criterion.getValues();
    if (value != null && EQ.equals(operator)) {
      query.setTags(singleton(value));
      return;
    }
    if (!values.isEmpty() && IN.equals(operator)) {
      query.setTags(new HashSet<>(values));
      return;
    }
    throw new IllegalArgumentException("Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)'");
  }

View on GitHub (pinned to 184c821202)

Solutions

  1. Use 'languages = java' for a single language or 'languages IN (java, js)' for several.
  2. Ensure the criterion includes at least one non-empty value.
  3. Remove or replace any other operator (<, >, !=) applied to the languages criterion.

Example fix

// before
String criteria = "languages != java";
// after
String criteria = "languages IN (java, js)";
Defensive patterns

Strategy: validation

Validate before calling

Set<String> allowed = Set.of("=", "IN");
if (criterion.getKey().equals("languages") && (!allowed.contains(criterion.getOperator()) || criterion.getValues().isEmpty())) {
  throw new IllegalArgumentException("languages requires '=' or 'IN' with at least one value");
}

Try / catch

try {
  response = ws.searchProjects(criteria);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("Languages should be set")) {
    criteria = "languages = " + languages[0]; // fall back to single-value form
  } else throw e;
}

Prevention

When it happens

Trigger: Calling api/measures/search_projects (or similar) with a criteria string like 'languages > java', 'languages != java', 'languages =', or 'languages IN ()'; sending languages with an unsupported operator in a saved filter.

Common situations: Typos in operator names in dashboard filters; scripts constructing filters programmatically with the wrong operator; confusion between filter fields that allow other operators.

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/d961377936b51868. Report an issue: GitHub.