SonarSource/sonarqube · error · IllegalArgumentException
Failed to set the New Code Definition. The given value is…
Error message
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.
What it means
SonarQube's Clean as You Code methodology restricts which New Code Definition values are permitted. NewCodeDefinitionResolver.buildNewCodePeriodDto validates the assembled DTO with CaycUtils.isNewCodePeriodCompliant and throws this IllegalArgumentException when the type/value combination is not CayC-compliant (e.g. an unsupported reference or date).
Solutions
- Choose a CayC-compliant option: PREVIOUS_VERSION, a NUMBER_OF_DAYS within the allowed limit, or a compliant REFERENCE branch.
- Check the Clean as You Code documentation for the permitted values and pick one.
- Fix the project-level or global newCodePeriod setting that feeds this resolver.
Example fix
// before POST /api/new_code_periods?type=NUMBER_OF_DAYS&value=365 // after POST /api/new_code_periods?type=NUMBER_OF_DAYS&value=30
Defensive patterns
Strategy: validation
Validate before calling
// before setting new code period
if (!CaycUtils.isNewCodePeriodCompliant(type, value)) {
throw new IllegalArgumentException("Value not Clean-as-You-Code compliant");
} Try / catch
try { resolver.dto(params); } catch (IllegalArgumentException e) { log.error("New Code Definition rejected: {}", e.getMessage()); } Prevention
- Only offer documentation-listed compliant options (PREVIOUS_VERSION, short NUMBER_OF_DAYS, compliant REFERENCE) in tooling.
- Validate existing settings after SonarQube upgrades as compliance rules evolve.
When it happens
Trigger: Resolving or setting the New Code Definition (dto() -> buildNewCodePeriodDto) with a type/value pair such as REFERENCE to a non-compliant branch, or a NUMBER_OF_DAYS/DATE value disallowed by Clean as You Code rules.
Common situations: Admins setting the new code period via api/new_code_periods to a value the methodology rejects; upgrades where a previously stored setting is re-resolved at project creation and now fails compliance.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- allowAllGroups can only be enabled when Auto-provisioning…
- allowAllGroups cannot be enabled when the GitLab URL is…
- allowedGroups cannot be empty when Auto-provisioning is…
- Cannot provide an Azure DevOps access token for project
- Failed to unset the New Code Definition. Your
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/52ad84904d6da1e6.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java:104
private NewCodePeriodDto buildNewCodePeriodDto(String projectUuid, String mainBranchUuid,
String defaultBranchName, String newCodeDefinitionType, @Nullable String newCodeDefinitionValue) {
boolean isCommunityEdition = editionProvider.get().filter(EditionProvider.Edition.COMMUNITY::equals).isPresent();
NewCodePeriodType newCodePeriodType = parseNewCodeDefinitionType(newCodeDefinitionType);
NewCodePeriodDto dto = new NewCodePeriodDto();
dto.setType(newCodePeriodType);
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();
}View on GitHub (pinned to 184c821202)