SonarSource/sonarqube · error · IllegalArgumentException
Failed to parse number of days:
Error message
Failed to parse number of days:
What it means
For NUMBER_OF_DAYS New Code Definitions, the value must be a parseable number of days. NewCodeDefinitionResolver.parseDays delegates to NewCodePeriodParser.parseDays and wraps any parse failure in this IllegalArgumentException, appending the offending value to the message.
Solutions
- Pass a plain integer string, e.g. '30', as the value for NUMBER_OF_DAYS.
- Strip any units or formatting from the value before sending.
- Validate the value client-side with a numeric parse before calling the API.
Example fix
// before
setValue("30 days")
// after
setValue("30") Defensive patterns
Strategy: validation
Validate before calling
// before sending NUMBER_OF_DAYS value
if (!value.matches("\\d+")) {
throw new IllegalArgumentException("Value must be a plain integer number of days");
} Try / catch
try { NewCodePeriodParser.parseDays(value); } catch (Exception e) { log.error("Not a valid day count: {}", value); } Prevention
- Strip units and whitespace from day counts before submission.
- Use numeric-only input fields for the new code period.
When it happens
Trigger: getNewCodeDefinitionValueProjectCreation receives a NUMBER_OF_DAYS type whose value string is not an integer (e.g. '30d', 'one month', '', '1,5').
Common situations: Users entering human-friendly durations ('30 days') in the new code period field; locales using comma decimals; API clients passing units with the number.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Cannot mint a GitLab access token: project
- Could not parse GitLab answer to verify read permission…
- Could not parse GitLab answer to verify token. Got a…
- Could not parse GitLab answer to verify token scopes. Got a…
- Could not parse GitLab answer to verify write permission…
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/6445c494b6ff6e24.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java:139
yield Optional.empty();
}
case NUMBER_OF_DAYS -> {
requireValue(type, value);
yield Optional.of(parseDays(value));
}
case REFERENCE_BRANCH -> {
Preconditions.checkArgument(value == null, UNEXPECTED_VALUE_ERROR_MESSAGE, type);
yield Optional.of(defaultBranchName);
}
default -> throw new IllegalStateException("Unexpected type: " + type);
};
}
private static String parseDays(String value) {
try {
return Integer.toString(NewCodePeriodParser.parseDays(value));
} catch (Exception e) {
throw new IllegalArgumentException("Failed to parse number of days: " + value);
}
}
private static void requireValue(NewCodePeriodType type, @Nullable String value) {
Preconditions.checkArgument(value != null, "New code definition type '%s' requires a newCodeDefinitionValue", type);
}
private static NewCodePeriodType parseNewCodeDefinitionType(String typeStr) {
NewCodePeriodType type;
try {
type = NewCodePeriodType.valueOf(typeStr.toUpperCase(Locale.US));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid type: " + typeStr);
}
validateType(type);
return type;
}
View on GitHub (pinned to 184c821202)