{"record":{"id":"7bce363dfed62c82","repo":"apache/dubbo","slug":"invalid-hex-byte-s-at-index-d-of-s","errorCode":null,"errorMessage":"invalid hex byte '%s' at index %d of '%s'","messagePattern":"invalid hex byte '(.+?)' at index (.+?) of '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java","lineNumber":1235,"sourceCode":"        sb.append(']');\n        return sb.toString();\n    }\n\n    public static int decodeHexNibble(final char c) {\n        // Character.digit() is not used here, as it addresses a larger\n        // set of characters (both ASCII and full-width latin letters).\n        byte[] hex2b = HEX2B;\n        return c < hex2b.length ? hex2b[c] : -1;\n    }\n\n    /**\n     * Decode a 2-digit hex byte from within a string.\n     */\n    public static byte decodeHexByte(CharSequence s, int pos) {\n        int hi = decodeHexNibble(s.charAt(pos));\n        int lo = decodeHexNibble(s.charAt(pos + 1));\n        if (hi == -1 || lo == -1) {\n            throw new IllegalArgumentException(\n                    String.format(\"invalid hex byte '%s' at index %d of '%s'\", s.subSequence(pos, pos + 2), pos, s));\n        }\n        return (byte) ((hi << 4) + lo);\n    }\n\n    /**\n     * Creates a comma-delimited string from one or more string values.\n     *\n     * @param one    the first string value\n     * @param others additional string values\n     * @return the combined string, or null if the first value is null\n     * @since 2.7.8\n     */\n    public static String toCommaDelimitedString(String one, String... others) {\n        if (one == null) {\n            return null;\n        }\n        if (others == null) {","sourceCodeStart":1217,"sourceCodeEnd":1253,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java#L1217-L1253","documentation":"Thrown by StringUtils.decodeHexByte(CharSequence s, int pos) when the two characters at pos and pos+1 are not valid hexadecimal digits. Each character is decoded via a lookup table (HEX2B); if either returns -1, the byte is invalid and an IllegalArgumentException is thrown with the offending substring, position, and full input.","triggerScenarios":"Passing a string where the characters at the specified position are not 0-9, a-f, A-F (or full-width equivalents); pos pointing at whitespace or a separator inside a hex string; off-by-one in pos that lands on a non-hex delimiter.","commonSituations":"Decoding a hex-encoded ID or hash with embedded dashes (e.g. UUID format) without stripping separators; malformed or truncated input from a network source; encoding mismatch (base64 passed where hex expected).","solutions":["Validate the input is purely hex before calling: s.toString().matches(\"^[0-9a-fA-F]+$\").","Strip separators (dashes, colons, spaces) from the input before decoding.","Verify pos and pos+1 are within bounds and point at hex characters."],"exampleFix":"// before\nbyte b = StringUtils.decodeHexByte(\"ab-cd\", 0);\n// the '-' at index 2 is not valid, but also pos alignment may be wrong\n\n// after\nString clean = \"ab-cd\".replace(\"-\", \"\");\nbyte b = StringUtils.decodeHexByte(clean, 0);","handlingStrategy":"validation","validationCode":"String s2 = s.toString();\nif (pos + 1 >= s2.length()) throw new IllegalArgumentException(\"pos out of range\");\nchar c1 = s2.charAt(pos), c2 = s2.charAt(pos + 1);\nif (!\"0123456789abcdefABCDEF\".contains(String.valueOf(c1)) ||\n    !\"0123456789abcdefABCDEF\".contains(String.valueOf(c2))) {\n    throw new IllegalArgumentException(\"non-hex character at pos \" + pos);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip non-hex delimiters (dashes, colons, spaces) before decoding.","Validate the full string is hex with a regex before calling decodeHexByte."],"tags":["encoding","hex-decode","validation","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}