{"record":{"id":"4b13556af527f6ec","repo":"SonarSource/sonarqube","slug":"invalid-type-s","errorCode":null,"errorMessage":"Invalid type: %s","messagePattern":"Invalid type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java","lineNumber":254,"sourceCode":"  }\n\n  private ProjectDto getProject(DbSession dbSession, String projectKey) {\n    return componentFinder.getProjectByKey(dbSession, projectKey);\n  }\n\n  private BranchDto getMainBranch(DbSession dbSession, ProjectDto project) {\n    return dbClient.branchDao().selectByProject(dbSession, project)\n      .stream().filter(BranchDto::isMain)\n      .findFirst()\n      .orElseThrow(() -> new NotFoundException(format(\"Main branch in project '%s' is not found\", project.getKey())));\n  }\n\n  private static NewCodePeriodType validateType(String typeStr, boolean isOverall, boolean isBranch) {\n    NewCodePeriodType type;\n    try {\n      type = NewCodePeriodType.valueOf(typeStr.toUpperCase(Locale.US));\n    } catch (IllegalArgumentException e) {\n      throw new IllegalArgumentException(\"Invalid type: \" + typeStr);\n    }\n\n    if (isOverall) {\n      checkType(\"Overall setting\", OVERALL_TYPES, type);\n    } else if (isBranch) {\n      checkType(\"Branches\", BRANCH_TYPES, type);\n    } else {\n      checkType(\"Projects\", PROJECT_TYPES, type);\n    }\n    return type;\n  }\n\n  private SnapshotDto getAnalysis(DbSession dbSession, String analysisUuid, ProjectDto project, BranchDto branch) {\n    SnapshotDto snapshotDto = dbClient.snapshotDao().selectByUuid(dbSession, analysisUuid)\n      .orElseThrow(() -> new NotFoundException(format(\"Analysis '%s' is not found\", analysisUuid)));\n    checkAnalysis(dbSession, project, branch, snapshotDto);\n    return snapshotDto;\n  }","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java#L236-L272","documentation":"validateType converts the submitted type string to a NewCodePeriodType enum (upper-cased first) and rethrows any IllegalArgumentException as 'Invalid type: <value>'. Only the enum's constant names are accepted, so free-form or lowercase-only variants that do not match a constant fail.","triggerScenarios":"Calling api/new_code_periods/set with a type parameter not matching any NewCodePeriodType constant — e.g. 'days', 'previous_version ' with trailing space, or 'since_previous_version'.","commonSituations":"Typos or abbreviations in CI pipelines; assuming snake_case HTTP-style keys instead of enum names; documentation drift between SonarQube versions where enum constants were renamed.","solutions":["Use one of the exact NewCodePeriodType names: PREVIOUS_VERSION, SPECIFIC_ANALYSIS, REFERENCE_BRANCH, or NUMBER_OF_DAYS.","Trim whitespace and avoid quoting errors in the type parameter.","Note that case does not matter (it is upper-cased), but spelling must match the enum constant exactly."],"exampleFix":"// before\ntype=days\n// after\ntype=NUMBER_OF_DAYS","handlingStrategy":"validation","validationCode":"const VALID = ['PREVIOUS_VERSION', 'SPECIFIC_ANALYSIS', 'REFERENCE_BRANCH', 'NUMBER_OF_DAYS'];\nif (!VALID.includes(String(params.type).trim().toUpperCase())) throw new Error('Invalid New Code Period type: ' + params.type);","typeGuard":"const isNCType = (t) => typeof t === 'string' && ['PREVIOUS_VERSION','SPECIFIC_ANALYSIS','REFERENCE_BRANCH','NUMBER_OF_DAYS'].includes(t.trim().toUpperCase());","tryCatchPattern":"try { ... } catch (e) { if (/^Invalid type: /.test(String(e.message))) { log('Use one of: PREVIOUS_VERSION, SPECIFIC_ANALYSIS, REFERENCE_BRANCH, NUMBER_OF_DAYS'); } throw e; }","preventionTips":["Use enum constant names, not UI labels or snake_case variants.","Trim the value; case is tolerated but spelling is not."],"tags":["webapi","new-code-period","enum","validation","sonarqube"],"backgroundTag":"invalid-enum-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}