{"record":{"id":"0e7b5bea8cb7cb8a","repo":"bazelbuild/bazel","slug":"invalid-base-d-want-2-base-36","errorCode":null,"errorMessage":"invalid base %d (want 2 <= base <= 36)","messagePattern":"invalid base (.+?) \\(want 2 <= base <= 36\\)","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/StarlarkInt.java","lineNumber":153,"sourceCode":"        if (base == 0 || base == prefixBase) {\n          base = prefixBase;\n          digits = s.substring(2); // strip prefix\n        }\n      }\n    }\n\n    // No prefix, no base? Use decimal.\n    if (digits == s && base == 0) {\n      // Don't infer base when input starts with '0' due to octal/decimal ambiguity.\n      if (s.length() > 1 && s.charAt(0) == '0') {\n        throw new NumberFormatException(\n            \"cannot infer base when string begins with a 0: \"\n                + Starlark.repr(stringForErrors, StarlarkSemantics.DEFAULT));\n      }\n      base = 10;\n    }\n    if (base < 2 || base > 36) {\n      throw new NumberFormatException(\n          String.format(\"invalid base %d (want 2 <= base <= 36)\", base));\n    }\n\n    // Do not allow Long.parseLong and new BigInteger to accept another +/- sign.\n    if (digits.startsWith(\"+\") || digits.startsWith(\"-\")) {\n      throw new NumberFormatException(\n          String.format(\n              \"invalid base-%d literal: %s\",\n              base, Starlark.repr(stringForErrors, StarlarkSemantics.DEFAULT)));\n    }\n\n    StarlarkInt result;\n    try {\n      result = StarlarkInt.of(Long.parseLong(digits, base));\n    } catch (NumberFormatException unused1) {\n      try {\n        result = StarlarkInt.of(new BigInteger(digits, base));\n      } catch (NumberFormatException unused2) {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/StarlarkInt.java#L135-L171","documentation":"StarlarkInt.parse validates the requested base and rejects anything outside 2..36 with NumberFormatException('invalid base %d (want 2 <= base <= 36)'). Long.parseLong/BigInteger support exactly this range of digit alphabets, so no other base can be honored.","triggerScenarios":"int(\"11\", 1), int(\"zz\", 36+1), int(s, 0 when a base was expected but a caller passed 0 meaning decimal-with-checks — note base 0 means 'infer', not invalid), or computing a base variable that lands out of range (e.g. len(alphabet) of a custom 64-char alphabet).","commonSituations":"Base64-style encodings mistakenly fed to int(s, 64); off-by-one loops using base as a loop counter; passing 0 and expecting decimal (0 means auto-infer and only errors on leading-zero strings).","solutions":["Clamp or validate the base before calling: if 2 <= base <= 36: int(s, base).","For base-64/64+ alphabets, write an explicit decoder — int() cannot do it.","If you want plain decimal, pass base 10 explicitly rather than 0."],"exampleFix":"# before\nval = int(token, len(ALPHABET))  # ALPHABET has 64 chars\n\n# after\nval = decode_custom_alphabet(token)  # explicit decoder for base-64\n# or, for standard bases:\nval = int(token, 16) if is_hex else int(token, 10)","handlingStrategy":"validation","validationCode":"def safe_int(s, base):\n    if base != 0 and not (2 <= base <= 36):\n        fail(\"base must be 2..36, got %d\" % base)\n    return int(s, base)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate computed bases (e.g. alphabet lengths) before calling int().","Remember base 0 means 'infer from prefix', and 10 means plain decimal."],"tags":["starlark","int-conversion","base","validation"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}