{"record":{"id":"73a59afdf35d01ae","repo":"apache/cassandra","slug":"invalid-token","errorCode":null,"errorMessage":"Invalid Token: ","messagePattern":"Invalid Token: ","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TokenUtf8Type.java","lineNumber":42,"sourceCode":"import org.apache.cassandra.serializers.MarshalException;\nimport org.apache.cassandra.serializers.TypeSerializer;\nimport org.apache.cassandra.serializers.UTF8Serializer;\nimport org.apache.cassandra.utils.ByteBufferUtil;\n\nimport static org.apache.cassandra.config.DatabaseDescriptor.getPartitioner;\n\npublic class TokenUtf8Type extends PseudoUtf8Type\n{\n    public static final TokenUtf8Type instance = new TokenUtf8Type();\n    static final TypeSerializer<String> tokenSerializer = new UTF8Serializer()\n    {\n        @Override\n        public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n        {\n            super.validate(value, accessor);\n            String str = deserialize(value, accessor);\n            if (null == getPartitioner().getTokenFactory().fromString(str))\n                throw new MarshalException(\"Invalid Token: \" + str);\n        }\n    };\n\n    private static final ArgumentDeserializer ARGUMENT_DESERIALIZER = new DefaultArgumentDeserializer(instance);\n    private static final ByteBuffer MASKED_VALUE = ByteBufferUtil.EMPTY_BYTE_BUFFER;\n\n    TokenUtf8Type() {} // singleton\n\n    String describe() { return \"Token\"; }\n\n    @Override\n    public TypeSerializer<String> getSerializer()\n    {\n        return tokenSerializer;\n    }\n\n    @Override\n    public <VL, VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TokenUtf8Type.java#L24-L60","documentation":"TokenUtf8Type validates that its UTF-8 string value can be converted back into a token by the current partitioner's token factory. If IPartitioner.getTokenFactory().fromString(str) returns null the value is rejected with this MarshalException.","triggerScenarios":"Binding a value to a token-typed column (e.g. for token-range queries via the token pseudo-type as string) with a malformed token literal such as '-99999999999999999999999' or non-numeric text for RandomPartitioner/Murmur3 tokens.","commonSituations":"Hand-built token-range queries where the token string was computed with a different partitioner; copy/pasted tokens with whitespace or wrong digit counts; scripts generating out-of-range token literals.","solutions":["Generate token literals with the same partitioner's TokenFactory.toString/fromString rather than hand-computing.","Validate with getPartitioner().getTokenFactory().fromString(s) != null on the client before binding.","Trim/normalize whitespace and ensure the literal matches the partitioner's token format (e.g. signed 64-bit for Murmur3Partitioner)."],"exampleFix":"// before\nString token = \"-92233720368547758080\"; // out of Murmur3 range\n// after\nToken t = Murmur3Partitioner.instance.getTokenFactory().fromString(token);\nif (t == null) throw new IllegalArgumentException(\"invalid token: \" + token);","handlingStrategy":"validation","validationCode":"boolean valid = tokenStr != null && DatabaseDescriptor.getPartitioner().getTokenFactory().fromString(tokenStr.trim()) != null;","typeGuard":null,"tryCatchPattern":"try { type.validate(bb, ByteBufferAccessor.instance); } catch (MarshalException e) { /* invalid token literal */ }","preventionTips":["Produce token literals via the partitioner's TokenFactory, never by hand","Use one partitioner consistently across tools generating tokens","Trim strings and range-check against Long.MIN/MAX for Murmur3 tokens"],"tags":["cassandra","validation","token","partitioner"],"backgroundTag":"invalid-argument-value","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"}