{"record":{"id":"527ef6cbb074c143","repo":"SonarSource/sonarqube","slug":"failed-to-unset-the-new-code-definition-your-s-n","errorCode":null,"errorMessage":"Failed to unset the New Code Definition. Your %s New Code Definition is not compatible with the Clean as You Code methodology. Please update your %s New Code Definition","messagePattern":"Failed to unset the New Code Definition\\. Your (.+?) New Code Definition is not compatible with the Clean as You Code methodology\\. Please update your (.+?) New Code Definition","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java","lineNumber":160,"sourceCode":"      .findFirst()\n      .orElseThrow(() -> new NotFoundException(format(\"Main branch in project '%s' not found\", project.getKey())));\n  }\n\n  private BranchDto getBranch(DbSession dbSession, ProjectDto project, String branchKey) {\n    return dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), branchKey)\n      .orElseThrow(() -> new NotFoundException(format(\"Branch '%s' in project '%s' not found\", branchKey, project.getKey())));\n  }\n\n  private ProjectDto getProject(DbSession dbSession, String projectKey) {\n    return componentFinder.getProjectByKey(dbSession, projectKey);\n  }\n\n  private void checkInstanceNcdCompliant(DbSession dbSession) {\n    var instanceNcd = newCodePeriodDao.selectGlobal(dbSession);\n    if (instanceNcd.isPresent()) {\n      var ncd = instanceNcd.get();\n      if (!CaycUtils.isNewCodePeriodCompliant(ncd.getType(), ncd.getValue())) {\n        throw new IllegalArgumentException(format(NON_COMPLIANT_CAYC_ERROR_MESSAGE, INSTANCE, INSTANCE));\n      }\n    }\n  }\n\n  private void checkBranchInheritedNcdCompliant(DbSession dbSession, String projectUuid) {\n    var projectNcd = newCodePeriodDao.selectByProject(dbSession, projectUuid);\n    if (projectNcd.isPresent()) {\n      var ncd = projectNcd.get();\n      if (!CaycUtils.isNewCodePeriodCompliant(ncd.getType(), ncd.getValue())) {\n        throw new IllegalArgumentException(format(NON_COMPLIANT_CAYC_ERROR_MESSAGE, PROJECT, PROJECT));\n      }\n    } else {\n      checkInstanceNcdCompliant(dbSession);\n    }\n  }\n\n}\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java#L142-L178","documentation":"When unsetting a project/branch New Code Definition, UnsetAction falls back to the instance-level definition. checkInstanceNcdCompliant verifies that global NCD is compatible with Clean as You Code (via CaycUtils.isNewCodePeriodCompliant); if it is not, the unset is refused because the project would inherit a non-compliant definition.","triggerScenarios":"POST api/new_code_periods/unset where the project/branch has no own NCD, no inherited parent NCD, and the instance-level NCD (from api/new_code_periods/set at global level) uses a non-CaYC-compliant type/value such as a specific number of days like 365.","commonSituations":"Instance upgraded to a SonarQube version enforcing CaYC while the global New Code Period was set to an old non-compliant value (e.g. 30/90 days is fine but 365 is not); admin tries to reset a project to inherit the global setting which is invalid.","solutions":["Update the instance-level New Code Definition (api/new_code_periods/set without project key) to a CaYC-compliant type/value, e.g. DAYS with value <= 30 (e.g. previous_version or 30 days)","Set a CaYC-compliant definition directly on the project instead of relying on inheritance, then retry the unset","Choose a compliant reference branch strategy (PREVIOUS_VERSION) as the global setting"],"exampleFix":"// before: unset fails because global NCD = DAYS 365\nPOST /api/new_code_periods/unset?project=my_project\n\n// after: fix global definition first\nPOST /api/new_code_periods/set?value=30&type=DAYS\nPOST /api/new_code_periods/unset?project=my_project","handlingStrategy":"try-catch","validationCode":"// check global NCD compliance before unsetting a project/branch\ndefaults = await get('/api/new_code_periods/show');\ncompliant = ['PREVIOUS_VERSION'].includes(defaults.type) || (defaults.type === 'DAYS' && Number(defaults.value) <= 30);","typeGuard":"function isCaYCCompliant(ncd) { return ncd.type === 'PREVIOUS_VERSION' || (ncd.type === 'DAYS' && Number(ncd.value) <= 30); }","tryCatchPattern":"try { await api.unsetNcd({ project }); } catch (e) { if (e.message.includes('Clean as You Code')) { await setInstanceNcd({ type: 'DAYS', value: '30' }); await api.unsetNcd({ project }); } else { throw e; } }","preventionTips":["Keep the instance-level NCD CaYC-compliant after upgrades","Check api/consent/cayc or NCD show endpoints before unsetting","Audit all NCD levels (instance, project, branch) when migrating to Clean as You Code"],"tags":["webapi","new-code-period","clean-as-you-code","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"}