{"record":{"id":"053df2f9a985f26c","repo":"apple/pkl","slug":"s-is-too-large-to-fit-into-a-version","errorCode":null,"errorMessage":"`%s` is too large to fit into a Version.","messagePattern":"`(.+?)` is too large to fit into a Version\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/Version.java","lineNumber":84,"sourceCode":"    this.major = major;\n    this.minor = minor;\n    this.patch = patch;\n    this.preRelease = preRelease;\n    this.build = build;\n  }\n\n  /**\n   * Parses the given string as a semantic version number.\n   *\n   * <p>Throws {@link IllegalArgumentException} if the given string could not be parsed as a\n   * semantic version number or is too large to fit into a {@link Version}.\n   */\n  public static Version parse(String version) {\n    var result = parseOrNull(version);\n    if (result != null) return result;\n\n    if (VERSION.matcher(version).matches()) {\n      throw new IllegalArgumentException(\n          String.format(\"`%s` is too large to fit into a Version.\", version));\n    }\n\n    throw new IllegalArgumentException(\n        String.format(\"`%s` could not be parsed as a semantic version number.\", version));\n  }\n\n  /**\n   * Parses the given string as a semantic version number.\n   *\n   * <p>Returns {@code null} if the given string could not be parsed as a semantic version number or\n   * is too large to fit into a {@link Version}.\n   */\n  public static @Nullable Version parseOrNull(String version) {\n    var matcher = VERSION.matcher(version);\n    if (!matcher.matches()) return null;\n\n    try {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/Version.java#L66-L102","documentation":"Version.parse first attempts parseOrNull; if that fails but the string still matches the VERSION regex shape, the numeric components exceed the ranges representable in Pkl's packed Version type. It throws IllegalArgumentException saying the version is \"too large to fit into a Version\".","triggerScenarios":"Version.parse(\"1.999999999999.0\") or similar — a syntactically valid semver string whose major/minor/patch components overflow the internal integer encoding.","commonSituations":"Parsing untrusted/user-supplied version strings; versions from external registries that use huge build counters; tests with sentinel versions like 99999.0.0.","solutions":["Use a version string whose major/minor/patch fit within supported ranges (small non-negative integers).","Pre-validate components with a regex and bound check before calling Version.parse, or use Version.parseOrNull and handle null.","Catch IllegalArgumentException and surface a user-friendly message asking for a conventional semver like 1.2.3."],"exampleFix":"// before\nVersion v = Version.parse(\"999999999999.1.0\"); // throws\n// after\nVersion v = Version.parse(\"9999.1.0\"); // within representable range","handlingStrategy":"validation","validationCode":"boolean isPlausibleVersion(String s) {\n  var m = Pattern.compile(\"^(\\\\d+)\\\\.(\\\\d+)\\\\.(\\\\d+)$\").matcher(s);\n  return m.matches()\n      && m.group(1).length() <= 4 && m.group(2).length() <= 4 && m.group(3).length() <= 4;\n}","typeGuard":"Version safeParse(String s) { var v = Version.parseOrNull(s); if (v == null) { log.warn(\"unusable version: {}\", s); } return v; }","tryCatchPattern":"try {\n  return Version.parse(input);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Version too large or malformed: \" + input, e);\n}","preventionTips":["Bound-check numeric components before parsing user-supplied versions.","Prefer parseOrNull for untrusted input.","Reject sentinel/extreme versions at config-validation time."],"tags":["versioning","parsing","overflow","pkl"],"backgroundTag":"value-out-of-range","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}