{"record":{"id":"52ad84904d6da1e6","repo":"SonarSource/sonarqube","slug":"failed-to-set-the-new-code-definition-the-given-v","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java","lineNumber":104,"sourceCode":"\n  private NewCodePeriodDto buildNewCodePeriodDto(String projectUuid, String mainBranchUuid,\n    String defaultBranchName, String newCodeDefinitionType, @Nullable String newCodeDefinitionValue) {\n\n    boolean isCommunityEdition = editionProvider.get().filter(EditionProvider.Edition.COMMUNITY::equals).isPresent();\n    NewCodePeriodType newCodePeriodType = parseNewCodeDefinitionType(newCodeDefinitionType);\n\n    NewCodePeriodDto dto = new NewCodePeriodDto();\n    dto.setType(newCodePeriodType);\n    dto.setProjectUuid(projectUuid);\n\n    if (isCommunityEdition) {\n      dto.setBranchUuid(mainBranchUuid);\n    }\n\n    getNewCodeDefinitionValueProjectCreation(newCodePeriodType, newCodeDefinitionValue, defaultBranchName).ifPresent(dto::setValue);\n\n    if (!CaycUtils.isNewCodePeriodCompliant(dto.getType(), dto.getValue())) {\n      throw new IllegalArgumentException(\"Failed to set the New Code Definition. The given value is not compatible with the Clean as You Code methodology. \"\n        + \"Please refer to the documentation for compliant options.\");\n    }\n\n    return dto;\n  }\n\n  public static void checkNewCodeDefinitionParam(@Nullable String newCodeDefinitionType, @Nullable String newCodeDefinitionValue) {\n    if (newCodeDefinitionType == null && newCodeDefinitionValue != null) {\n      throw new IllegalArgumentException(\"New code definition type is required when new code definition value is provided\");\n    }\n  }\n\n  private static Optional<String> getNewCodeDefinitionValueProjectCreation(NewCodePeriodType type, @Nullable String value, String defaultBranchName) {\n    return switch (type) {\n      case PREVIOUS_VERSION -> {\n        Preconditions.checkArgument(value == null, UNEXPECTED_VALUE_ERROR_MESSAGE, type);\n        yield Optional.empty();\n      }","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java#L86-L122","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nPOST /api/new_code_periods?type=NUMBER_OF_DAYS&value=365\n\n// after\nPOST /api/new_code_periods?type=NUMBER_OF_DAYS&value=30","handlingStrategy":"validation","validationCode":"// before setting new code period\nif (!CaycUtils.isNewCodePeriodCompliant(type, value)) {\n  throw new IllegalArgumentException(\"Value not Clean-as-You-Code compliant\");\n}","typeGuard":null,"tryCatchPattern":"try { resolver.dto(params); } catch (IllegalArgumentException e) { log.error(\"New Code Definition rejected: {}\", e.getMessage()); }","preventionTips":["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."],"tags":["new-code-definition","clean-as-you-code","validation","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}