{"record":{"id":"bc26bd07a3b5f6ee","repo":"chinabugotech/hutool","slug":"invalid-char-at","errorCode":null,"errorMessage":"Invalid char '{}' at [{}]","messagePattern":"Invalid char '(.+?)' at \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/codec/Base58Codec.java","lineNumber":137,"sourceCode":"\t\t\tfinal int length = alphabet.length();\n\t\t\tfor (int i = 0; i < length; i++) {\n\t\t\t\tlookupTable[alphabet.charAt(i)] = (byte) i;\n\t\t\t}\n\t\t\tthis.lookupTable = lookupTable;\n\t\t}\n\n\t\t@Override\n\t\tpublic byte[] decode(CharSequence encoded) {\n\t\t\tif (encoded.length() == 0) {\n\t\t\t\treturn new byte[0];\n\t\t\t}\n\t\t\t// Convert the base58-encoded ASCII chars to a base58 byte sequence (base58 digits).\n\t\t\tfinal byte[] input58 = new byte[encoded.length()];\n\t\t\tfor (int i = 0; i < encoded.length(); ++i) {\n\t\t\t\tchar c = encoded.charAt(i);\n\t\t\t\tint digit = c < 128 ? lookupTable[c] : -1;\n\t\t\t\tif (digit < 0) {\n\t\t\t\t\tthrow new IllegalArgumentException(StrUtil.format(\"Invalid char '{}' at [{}]\", c, i));\n\t\t\t\t}\n\t\t\t\tinput58[i] = (byte) digit;\n\t\t\t}\n\t\t\t// Count leading zeros.\n\t\t\tint zeros = 0;\n\t\t\twhile (zeros < input58.length && input58[zeros] == 0) {\n\t\t\t\t++zeros;\n\t\t\t}\n\t\t\t// Convert base-58 digits to base-256 digits.\n\t\t\tbyte[] decoded = new byte[encoded.length()];\n\t\t\tint outputStart = decoded.length;\n\t\t\tfor (int inputStart = zeros; inputStart < input58.length; ) {\n\t\t\t\tdecoded[--outputStart] = divmod(input58, inputStart, 58, 256);\n\t\t\t\tif (input58[inputStart] == 0) {\n\t\t\t\t\t++inputStart; // optimization - skip leading zeros\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Ignore extra leading zeroes that were added during the calculation.","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/codec/Base58Codec.java#L119-L155","documentation":"Base58Codec's decoder maps each input char through a lookup table; chars not in the Base58 alphabet (excludes 0, O, I, l and all non-alphanumeric) or any char >= 128 yield digit -1 and an IllegalArgumentException naming the char and index. This is the decode-side input validation, distinct from the checksum check (error 37).","triggerScenarios":"Decoding a string with whitespace, 0/O/I/l, punctuation, or non-ASCII chars via Base58Codec.decode / Base58.decode. A copy-paste that included spaces or newlines.","commonSituations":"User-supplied Base58 with formatting whitespace; mistaking Base64/Base32 output for Base58; locale-specific characters in the input.","solutions":["Trim and strip all whitespace before decoding.","Validate the input matches the Base58 alphabet regex ^[1-9A-HJ-NP-Za-km-z]+$ before calling decode.","Reject inputs containing the forbidden look-alike chars (0,O,I,l)."],"exampleFix":"// before\nbyte[] d = Base58.decode(\" 1BvBMSE  YstWetqTFn5\\n\");\n// after\nString clean = userInput.trim().replaceAll(\"\\\\s\", \"\");\nif (!clean.matches(\"^[1-9A-HJ-NP-Za-km-z]+$\")) throw new IllegalArgumentException(\"bad base58\");\nbyte[] d = Base58.decode(clean);","handlingStrategy":"validation","validationCode":"String clean = input.trim().replaceAll(\"\\\\s\", \"\");\nif (!clean.matches(\"^[1-9A-HJ-NP-Za-km-z]+$\")) throw new IllegalArgumentException(\"invalid base58 char in: \" + input);","typeGuard":"static boolean isBase58(String s) { return s != null && s.matches(\"^[1-9A-HJ-NP-Za-km-z]+$\"); }","tryCatchPattern":"try { return Base58.decode(s); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(\"bad base58\", e); }","preventionTips":["Trim whitespace and validate the Base58 alphabet (no 0,O,I,l) before decode.","Do not feed Base64/Base32 strings into a Base58 decoder."],"tags":["base58","codec","decoder","argument-validation"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}