{"record":{"id":"3d37177237e74f68","repo":"MyCATApache/Mycat-Server","slug":"illegal-hex-string-hexstring","errorCode":null,"errorMessage":"illegal hex-string: {hexString}","messagePattern":"illegal hex-string: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/util/ParseString.java","lineNumber":108,"sourceCode":"                break;\n            case 'c':\n            case 'C':\n                b = 0xc0;\n                break;\n            case 'd':\n            case 'D':\n                b = 0xd0;\n                break;\n            case 'e':\n            case 'E':\n                b = 0xe0;\n                break;\n            case 'f':\n            case 'F':\n                b = 0xf0;\n                break;\n            default:\n                throw new IllegalArgumentException(\"illegal hex-string: \" + new String(hexString, offset, length));\n            }\n            switch (low) {\n            case '0':\n                break;\n            case '1':\n                b += 1;\n                break;\n            case '2':\n                b += 2;\n                break;\n            case '3':\n                b += 3;\n                break;\n            case '4':\n                b += 4;\n                break;\n            case '5':\n                b += 5;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/util/ParseString.java#L90-L126","documentation":"ParseString.hexString2Bytes converts a hexadecimal string to bytes, validating each nibble against 0-9a-fA-F. When any character is outside the hex alphabet, it throws IllegalArgumentException('illegal hex-string: ...') with the offending substring. Note this is a RuntimeException, not SQLNonTransientException.","triggerScenarios":"Calling hexString2Bytes (public) with a string containing a non-hex character at/after the given offset — e.g. '0x1G', 'zz', a string with 0x prefix not stripped, whitespace, or odd characters embedded in hex literals used by rule/config parsing.","commonSituations":"Hex literals in sharding rule config that include the '0x' prefix; corrupted/typo'd hex values; copying hex strings with trailing spaces or newlines; binary data pasted with non-hex characters.","solutions":["Strip the '0x' prefix and any whitespace before passing the string","Verify every character is [0-9a-fA-F] (and that the length is even) before calling","Correct the typo'd/corrupted hex value in the config or input"],"exampleFix":"// before\nbyte[] b = ParseString.hexString2Bytes(\"0x1A2F\", 0, 6);\n// after\nString hex = \"0x1A2F\".replaceFirst(\"^0x\",\"\").trim();\nif (!hex.matches(\"[0-9a-fA-F]+\") || hex.length()%2!=0) throw new IllegalArgumentException(\"bad hex\");\nbyte[] b = ParseString.hexString2Bytes(hex, 0, hex.length());","handlingStrategy":"validation","validationCode":"void assertHex(String s) {\n    String h = s.replaceFirst(\"(?i)^0x\",\"\").trim();\n    if (!h.matches(\"[0-9a-fA-F]+\") || h.length()%2!=0)\n        throw new IllegalArgumentException(\"illegal hex-string: \" + s);\n}","typeGuard":"boolean isHexString(String s) {\n    return s != null && s.replaceFirst(\"(?i)^0x\",\"\").matches(\"[0-9a-fA-F]+\");\n}","tryCatchPattern":"try { byte[] b = ParseString.hexString2Bytes(hex, 0, hex.length()); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"illegal hex-string\")) { sanitizeAndRetry(e.getMessage()); } }","preventionTips":["Strip '0x' prefixes and whitespace from hex inputs","Regex-validate hex strings before conversion","Keep hex config values clean of trailing spaces/newlines"],"tags":["parsing","hex","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}