{"record":{"id":"54abc0d89520901c","repo":"alibaba/DataX","slug":"failed-to-parse-delimiter-hex-str-length-error","errorCode":null,"errorMessage":"Failed to parse delimiter: `Hex str length error`","messagePattern":"Failed to parse delimiter: `Hex str length error`","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"doriswriter/src/main/java/com/alibaba/datax/plugin/writer/doriswriter/DelimiterParser.java","lineNumber":24,"sourceCode":"\npublic class DelimiterParser {\n\n    private static final String HEX_STRING = \"0123456789ABCDEF\";\n\n    public static String parse(String sp, String dSp) throws RuntimeException {\n        if ( Strings.isNullOrEmpty(sp)) {\n            return dSp;\n        }\n        if (!sp.toUpperCase().startsWith(\"\\\\X\")) {\n            return sp;\n        }\n        String hexStr = sp.substring(2);\n        // check hex str\n        if (hexStr.isEmpty()) {\n            throw new RuntimeException(\"Failed to parse delimiter: `Hex str is empty`\");\n        }\n        if (hexStr.length() % 2 != 0) {\n            throw new RuntimeException(\"Failed to parse delimiter: `Hex str length error`\");\n        }\n        for (char hexChar : hexStr.toUpperCase().toCharArray()) {\n            if (HEX_STRING.indexOf(hexChar) == -1) {\n                throw new RuntimeException(\"Failed to parse delimiter: `Hex str format error`\");\n            }\n        }\n        // transform to separator\n        StringWriter writer = new StringWriter();\n        for (byte b : hexStrToBytes(hexStr)) {\n            writer.append((char) b);\n        }\n        return writer.toString();\n    }\n\n    private static byte[] hexStrToBytes(String hexStr) {\n        String upperHexStr = hexStr.toUpperCase();\n        int length = upperHexStr.length() / 2;\n        char[] hexChars = upperHexStr.toCharArray();","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/alibaba/DataX/blob/80ec23d5c5328eb90ca364d2749e92dfaf44541e/doriswriter/src/main/java/com/alibaba/datax/plugin/writer/doriswriter/DelimiterParser.java#L6-L42","documentation":"DelimiterParser.parse throws this when a hex-mode separator (prefix \\x) is followed by an odd number of hex characters. Hex encoding maps two characters to one byte, so lengths like 1 or 3 cannot be decoded and parsing fails with 'Hex str length error'.","triggerScenarios":"column_separator values such as \"\\\\x1\" (1 digit) or \"\\\\xabc\" (3 digits) in the doriswriter loadProps. The empty case is caught earlier; this fires only when the remaining substring's length % 2 != 0.","commonSituations":"Typos dropping one digit from a two-digit hex code (\"\\\\x0\" instead of \"\\\\x0a\"), copy-paste truncation, or intending three ASCII characters but accidentally including the \\x prefix.","solutions":["Pad to an even number of hex digits: \"\\\\x1\" -> \"\\\\x01\".","Double-check each hex byte against an ASCII table when choosing control-character delimiters.","If a multi-character ASCII separator was intended, drop the \\x prefix entirely (e.g. \"|||\") — non-hex values pass through unchanged.","Validate the delimiter with a quick hex-length check before deploying the job."],"exampleFix":"// before\n\"loadProps\": { \"column_separator\": \"\\\\x1\" }\n// after\n\"loadProps\": { \"column_separator\": \"\\\\x01\" }","handlingStrategy":"validation","validationCode":"String hex = sp.substring(2);\nif (hex.length() % 2 != 0) throw new IllegalArgumentException(\"hex delimiter must have even digit count: \" + sp);","typeGuard":"boolean isEvenLengthHex(String sp) { return sp.toUpperCase().startsWith(\"\\\\X\") && sp.substring(2).matches(\"[0-9A-Fa-f]*\") && sp.substring(2).length() % 2 == 0; }","tryCatchPattern":null,"preventionTips":["Write hex delimiters as two digits per byte and lint for odd lengths.","Prefer well-known control characters (\\\\x01, \\\\x1f) instead of ad-hoc hex values."],"tags":["datax","doris","writer","configuration","delimiter"],"backgroundTag":null,"analyzedSha":"80ec23d5c5328eb90ca364d2749e92dfaf44541e","analyzedAt":"2026-08-14T15:33:51.187Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}