{"record":{"id":"6445c494b6ff6e24","repo":"SonarSource/sonarqube","slug":"failed-to-parse-number-of-days","errorCode":null,"errorMessage":"Failed to parse number of days: ","messagePattern":"Failed to parse number of days: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java","lineNumber":139,"sourceCode":"        yield Optional.empty();\n      }\n      case NUMBER_OF_DAYS -> {\n        requireValue(type, value);\n        yield Optional.of(parseDays(value));\n      }\n      case REFERENCE_BRANCH -> {\n        Preconditions.checkArgument(value == null, UNEXPECTED_VALUE_ERROR_MESSAGE, type);\n        yield Optional.of(defaultBranchName);\n      }\n      default -> throw new IllegalStateException(\"Unexpected type: \" + type);\n    };\n  }\n\n  private static String parseDays(String value) {\n    try {\n      return Integer.toString(NewCodePeriodParser.parseDays(value));\n    } catch (Exception e) {\n      throw new IllegalArgumentException(\"Failed to parse number of days: \" + value);\n    }\n  }\n\n  private static void requireValue(NewCodePeriodType type, @Nullable String value) {\n    Preconditions.checkArgument(value != null, \"New code definition type '%s' requires a newCodeDefinitionValue\", type);\n  }\n\n  private static NewCodePeriodType parseNewCodeDefinitionType(String typeStr) {\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    validateType(type);\n    return type;\n  }\n","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-common/src/main/java/org/sonar/server/common/newcodeperiod/NewCodeDefinitionResolver.java#L121-L157","documentation":"For NUMBER_OF_DAYS New Code Definitions, the value must be a parseable number of days. NewCodeDefinitionResolver.parseDays delegates to NewCodePeriodParser.parseDays and wraps any parse failure in this IllegalArgumentException, appending the offending value to the message.","triggerScenarios":"getNewCodeDefinitionValueProjectCreation receives a NUMBER_OF_DAYS type whose value string is not an integer (e.g. '30d', 'one month', '', '1,5').","commonSituations":"Users entering human-friendly durations ('30 days') in the new code period field; locales using comma decimals; API clients passing units with the number.","solutions":["Pass a plain integer string, e.g. '30', as the value for NUMBER_OF_DAYS.","Strip any units or formatting from the value before sending.","Validate the value client-side with a numeric parse before calling the API."],"exampleFix":"// before\nsetValue(\"30 days\")\n\n// after\nsetValue(\"30\")","handlingStrategy":"validation","validationCode":"// before sending NUMBER_OF_DAYS value\nif (!value.matches(\"\\\\d+\")) {\n  throw new IllegalArgumentException(\"Value must be a plain integer number of days\");\n}","typeGuard":null,"tryCatchPattern":"try { NewCodePeriodParser.parseDays(value); } catch (Exception e) { log.error(\"Not a valid day count: {}\", value); }","preventionTips":["Strip units and whitespace from day counts before submission.","Use numeric-only input fields for the new code period."],"tags":["new-code-definition","number-format","parsing"],"backgroundTag":"invalid-argument-format","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"}