{"record":{"id":"fd7ff824f6c24bff","repo":"apache/cassandra","slug":"invalid-tokenrange","errorCode":null,"errorMessage":"Invalid TokenRange: ","messagePattern":"Invalid TokenRange: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/accord/TokenRange.java","lineNumber":208,"sourceCode":"        public long serializedSize(TokenRange t)\n        {\n            return TokenKey.noTableSerializer.serializedSize(t.start())\n                   + TokenKey.noTableSerializer.serializedSize(t.end());\n        }\n    };\n\n    public static TokenRange parse(String str, IPartitioner partitioner)\n    {\n        TableId tableId;\n        {\n            int split = str.indexOf(':', str.startsWith(\"tid:\") ? 4 : 0);\n            tableId = TableId.fromString(str.substring(0, split));\n            str = str.substring(split + 2, str.length() - 1);\n        }\n\n        String[] bounds = str.split(\",\");\n        if (bounds.length != 2)\n            throw new IllegalArgumentException(\"Invalid TokenRange: \" + str);\n\n        return new TokenRange(TokenKey.parse(tableId, bounds[0], partitioner), TokenKey.parse(tableId, bounds[1], partitioner));\n    }\n\n}\n","sourceCodeStart":190,"sourceCodeEnd":214,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/accord/TokenRange.java#L190-L214","documentation":"TokenRange.parse() validates that a serialized token range string contains exactly two comma-separated bounds after the optional TableId:: prefix. If the split produces a different number of parts, the string is malformed and IllegalArgumentException('Invalid TokenRange: <str>') is thrown. This is a strict format check on human/tool-provided range strings like 'tableId::[start, end]'.","triggerScenarios":"Passing a malformed string to TokenRange.parse (e.g. missing a bound like 'tbl::[10,)' or '(10]', extra commas, wrong bracket placement, missing both bounds), typically from node-tool output parsing, JMX, or hand-written scripts.","commonSituations":"Parsing ranges copy-pasted from logs with truncated output; building range strings programmatically with null/empty bounds; format changes between Cassandra versions altering the serialized form; typos in hand-written range arguments.","solutions":["Provide a well-formed string of the form '<tableId>::[<start>, <end>]' (or '[<start>, <end>]' without tableId) with exactly two bounds","Print/log the failing string from the exception message and fix the offending producer (script, tool, or serializer)","Trim whitespace and strip stray brackets before parsing","Regenerate the range list from ClusterMetadata/TokenRange.toString() rather than hand-crafting strings"],"exampleFix":"// before\nTokenRange range = TokenRange.parse(partitioner, \"tbl::[9223372036854775807,)\");\n// IllegalArgumentException: Invalid TokenRange: [9223372036854775807,)\n// after\nTokenRange range = TokenRange.parse(partitioner, \"tbl::[9223372036854775807, -9223372036854775808]\");","handlingStrategy":"validation","validationCode":"String[] bounds = str.substring(str.indexOf(\"[\") + 1, str.length() - 1).split(\",\");\nif (bounds.length != 2) throw new IllegalArgumentException(\"expected [start, end]: \" + str);\nTokenRange r = TokenRange.parse(partitioner, str);","typeGuard":null,"tryCatchPattern":"try { return TokenRange.parse(partitioner, str); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(\"Malformed token range '\" + str + \"': expected '<tableId>::[<start>, <end>]'\", e); }","preventionTips":["Generate range strings from TokenRange.toString() instead of hand-building them","Validate the '<tableId>::[<start>, <end>]' shape before parsing","Beware truncated log output when copying ranges","Trim whitespace and stray brackets from user input"],"tags":["parsing","token-range","illegal-argument","format"],"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-14T21:17:11.552Z"}