SonarSource/sonarqube · error · IllegalArgumentException
New code definition type is required when new code…
Error message
New code definition type is required when new code definition value is provided
What it means
The New Code Definition requires both a type and, for most types, a value. NewCodeDefinitionResolver.checkNewCodeDefinitionParam enforces that a value is never submitted without a type, throwing this IllegalArgumentException when newCodeDefinitionType is null but newCodeDefinitionValue is present.
Solutions
- Provide newCodeDefinitionType (e.g. NUMBER_OF_DAYS, PREVIOUS_VERSION, REFERENCE, SPECIFIC_ANALYSIS) together with the value.
- Remove the value entirely if no type change is intended.
Example fix
// before
checkNewCodeDefinitionParam(null, "30")
// after
checkNewCodeDefinitionParam("NUMBER_OF_DAYS", "30") Defensive patterns
Strategy: validation
Validate before calling
// before submit
if (value != null && (type == null || type.isBlank())) {
throw new IllegalArgumentException("Type required when value provided");
} Try / catch
try { NewCodeDefinitionResolver.checkNewCodeDefinitionParam(type, value); } catch (IllegalArgumentException e) { promptForType(); } Prevention
- Send type and value together in API calls.
- Make the type field mandatory in forms whenever a value is filled.
When it happens
Trigger: Calling the resolver/API with newCodeDefinitionValue set (e.g. '30' or a branch name) while omitting newCodeDefinitionType.
Common situations: Scripts that update only the value assuming the type is remembered; partially filled web forms; API clients that serialize empty type strings as null.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Failed to set the New Code Definition. The given value is…
- If branch key is specified, project key needs to be…
- Invalid type:
- The ' ' parameter is missing
- a JVM option can't be empty and must start with '-'. The…
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/0f1f81e131ebfdf5.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java:113
dto.setProjectUuid(projectUuid);
if (isCommunityEdition) {
dto.setBranchUuid(mainBranchUuid);
}
getNewCodeDefinitionValueProjectCreation(newCodePeriodType, newCodeDefinitionValue, defaultBranchName).ifPresent(dto::setValue);
if (!CaycUtils.isNewCodePeriodCompliant(dto.getType(), dto.getValue())) {
throw new IllegalArgumentException("Failed to set the New Code Definition. The given value is not compatible with the Clean as You Code methodology. "
+ "Please refer to the documentation for compliant options.");
}
return dto;
}
public static void checkNewCodeDefinitionParam(@Nullable String newCodeDefinitionType, @Nullable String newCodeDefinitionValue) {
if (newCodeDefinitionType == null && newCodeDefinitionValue != null) {
throw new IllegalArgumentException("New code definition type is required when new code definition value is provided");
}
}
private static Optional<String> getNewCodeDefinitionValueProjectCreation(NewCodePeriodType type, @Nullable String value, String defaultBranchName) {
return switch (type) {
case PREVIOUS_VERSION -> {
Preconditions.checkArgument(value == null, UNEXPECTED_VALUE_ERROR_MESSAGE, type);
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);View on GitHub (pinned to 184c821202)