{"record":{"id":"88ae104c642970d6","repo":"apache/cassandra","slug":"token-token-contains-non-hex-digits","errorCode":null,"errorMessage":"Token \" + token + \" contains non-hex digits","messagePattern":"Token \" \\+ token \\+ \" contains non-hex digits","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java","lineNumber":346,"sourceCode":"        }\n\n        public String toString(Token token)\n        {\n            BytesToken bytesToken = (BytesToken) token;\n            return Hex.bytesToHex(bytesToken.token);\n        }\n\n        public void validate(String token) throws ConfigurationException\n        {\n            try\n            {\n                if (token.length() % 2 == 1)\n                    token = \"0\" + token;\n                Hex.hexToBytes(token);\n            }\n            catch (NumberFormatException e)\n            {\n                throw new ConfigurationException(\"Token \" + token + \" contains non-hex digits\");\n            }\n        }\n\n        public Token fromString(String string)\n        {\n            if (string.length() % 2 == 1)\n                string = \"0\" + string;\n            return new BytesToken(Hex.hexToBytes(string));\n        }\n    };\n\n    public Token.TokenFactory getTokenFactory()\n    {\n        return tokenFactory;\n    }\n\n    @Override\n    public boolean accordSupported()","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java#L328-L364","documentation":"ByteOrderedPartitioner's token validator normalizes a hex token string (padding odd length) and then decodes it with Hex.hexToBytes; a NumberFormatException there means the string contains characters outside [0-9a-fA-F]. It is rethrown as a ConfigurationException since the token normally comes from cassandra.yaml's initial_token.","triggerScenarios":"Setting initial_token to a non-hex string (e.g. decimal number, '0x...' prefix, whitespace or stray characters) with ByteOrderedPartitioner; calling TokenFactory.validate(token) programmatically with a malformed string.","commonSituations":"Copy-pasting a token from decimal notation used by RandomPartitioner/Murmur3Partitioner into a BOP cluster; hand-editing cassandra.yaml; '0x' prefix that Hex does not accept.","solutions":["Rewrite initial_token as a valid hexadecimal string (even-length, e.g. '00ffab'), matching the BOP token format.","Remove the 0x prefix and strip whitespace before the value.","If the token came from another partitioner, regenerate it — token formats are not interchangeable between partitioners.","Or omit initial_token and let the node pick tokens randomly (if manual byte-order placement is not required)."],"exampleFix":"// before (cassandra.yaml)\ninitial_token: 123456789012   # decimal, rejected\n// after\ninitial_token: 0123456789012  # valid hex, padded to even length","handlingStrategy":"validation","validationCode":"public static boolean isValidHexToken(String token) {\n    String t = token.trim();\n    if (t.startsWith(\"0x\")) t = t.substring(2);\n    if (t.isEmpty() || t.length() % 2 != 0) return false;\n    return t.chars().allMatch(c -> Character.digit(c, 16) != -1);\n}","typeGuard":"boolean isHexString(String s) { return s != null && !s.isEmpty() && s.chars().allMatch(c -> Character.digit(c, 16) != -1); }","tryCatchPattern":"try {\n    factory.validate(initialToken);\n} catch (ConfigurationException e) {\n    throw new IllegalArgumentException(\"initial_token must be a valid even-length hex string\", e);\n}","preventionTips":["Validate initial_token in CI/config linting before deploying cassandra.yaml.","Never copy tokens between clusters with different partitioners.","Strip 0x prefixes and whitespace from token strings."],"tags":["token","hex","configuration","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}