SonarSource/sonarqube · error · IllegalArgumentException
Tags should be set either by using 'tags = java' or 'tags IN
Error message
Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)'
What it means
The tags criterion in the project measures/search WS must use either '=' with one tag or 'IN' with a non-empty tag list. processTags throws this IllegalArgumentException when another operator is used or the value list is empty.
Source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java:115
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)'");
}
private static void processQualifier(Criterion criterion, ProjectMeasuresQuery query) {
checkOperator(criterion);
checkValue(criterion);
Operator operator = criterion.getOperator();
String value = criterion.getValue();
checkArgument(EQ.equals(operator), "Only equals operator is available for qualifier criteria");
String qualifier = Stream.of(ComponentQualifiers.APP, ComponentQualifiers.PROJECT).filter(q -> q.equalsIgnoreCase(value)).findFirst()
.orElseThrow(() -> new IllegalArgumentException(format("Unknown qualifier : '%s'", value)));
query.setQualifiers(Sets.newHashSet(qualifier));
}
private static void processQuery(Criterion criterion, ProjectMeasuresQuery query) {
checkOperator(criterion);
Operator operatorValue = criterion.getOperator();
String value = criterion.getValue();
checkArgument(value != null, "Query is invalid");View on GitHub (pinned to 184c821202)
Solutions
- Use 'tags = finance' for one tag or 'tags IN (finance, platform)' for several.
- Ensure at least one tag value is present and non-empty.
- Only use comparison operators (=, IN) for tags, not relational ones.
Example fix
// before String criteria = "tags > finance"; // after String criteria = "tags IN (finance, platform)";
Defensive patterns
Strategy: validation
Validate before calling
Set<String> allowed = Set.of("=", "IN");
if (criterion.getKey().equals("tags") && (!allowed.contains(criterion.getOperator()) || criterion.getValues().isEmpty())) {
throw new IllegalArgumentException("tags requires '=' or 'IN' with at least one tag");
} Try / catch
try {
response = ws.searchProjects(criteria);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Tags should be set")) {
criteria = criteria.replaceAll("tags\\s*[^=I][^N]?.*", "tags IN (" + String.join(", ", tags) + ")");
} else throw e;
} Prevention
- Only generate 'tags = X' or 'tags IN (X, Y)' forms.
- Check the tag list is non-empty before building the criterion.
- Do not copy operators from numeric criteria (>, <) onto tags.
When it happens
Trigger: Calling api/measures/search_projects with criteria like 'tags > finance', 'tags != platform', 'tags =' (no value), or 'tags IN ()'.
Common situations: Hand-edited saved filters; scripting against the WS with operators copied from numeric criteria (where >, < are valid); empty tag variables interpolated into the criteria string.
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
- Languages should be set either by using 'languages = java' o
- Message '%s' cannot be dismissed.
- ${e.getMessage()}
- Cannot parse '%s' : %s
- Value '%s' is not a number
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/0cf8afc5709ef279.
Report an issue: GitHub.