{"record":{"id":"7ef721b05f567409","repo":"apache/cassandra","slug":"token-type-s-does-not-support-token-allocation-7ef721","errorCode":null,"errorMessage":"Token type %s does not support token allocation.","messagePattern":"Token type (.+?) does not support token allocation\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/dht/ComparableObjectToken.java","lineNumber":73,"sourceCode":"    public int hashCode()\n    {\n        return token.hashCode();\n    }\n\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public int compareTo(Token o)\n    {\n        if (o.getClass() != getClass())\n            throw new IllegalArgumentException(String.format(\"Invalid type of Token.compareTo() argument. %s != %s\", o.getClass(), getClass()));\n\n        return token.compareTo(((ComparableObjectToken<C>) o).token);\n    }\n\n    @Override\n    public double size(Token next)\n    {\n        throw new UnsupportedOperationException(String.format(\"Token type %s does not support token allocation.\",\n                                                              getClass().getSimpleName()));\n    }\n\n    @Override\n    public Token nextValidToken()\n    {\n        throw new UnsupportedOperationException(String.format(\"Token type %s does not support token allocation.\",\n                                                              getClass().getSimpleName()));\n    }\n\n    @Override\n    public Token decreaseSlightly()\n    {\n        throw new UnsupportedOperationException(String.format(\"Token type %s does not support token allocation.\",\n                                                              getClass().getSimpleName()));\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/dht/ComparableObjectToken.java#L55-L91","documentation":"ComparableObjectToken overrides size(Token) to always throw UnsupportedOperationException: object-backed tokens (e.g. LocalPartitioner tokens) have no meaningful numeric ring size for the token-allocation algorithms. This is the default 'allocation not supported' stub inherited by such token implementations.","triggerScenarios":"Calling size() on any ComparableObjectToken instance (e.g. LocalPartitioner tokens), directly or via TokenAllocation.allocateTokens / replication-factor-based token allocation during bootstrap.","commonSituations":"Using allocate_tokens_for_local_replication_factor or custom allocation code with LocalPartitioner (keyspaces backed by local data) or another object-token partitioner; tools assuming numeric tokens.","solutions":["Do not use token allocation with this partitioner; assign tokens explicitly.","Restructure code to only invoke allocation for numeric-token partitioners (check token type before calling size()).","Override size() in a custom Token subclass if you implement your own allocation-aware token type."],"exampleFix":"// before\ndouble size = token.size(next);  // throws for object tokens\n// after\ndouble size = token instanceof ComparableObjectToken ? 0.0 /* non-allocatable */ : token.size(next);","handlingStrategy":"type-guard","validationCode":"if (token instanceof ComparableObjectToken)\n    throw new IllegalStateException(\"Token allocation unsupported for object tokens\");","typeGuard":"boolean isAllocatable(Token t) { return t instanceof Murmur3Partitioner.LongToken; }","tryCatchPattern":"try {\n    double s = token.size(next);\n} catch (UnsupportedOperationException e) {\n    // object tokens are not allocation-aware\n}","preventionTips":["Do not enable token allocation on LocalPartitioner/object-token partitioners.","Feature-detect token type before running allocation tooling."],"tags":["token","token-allocation","unsupported-operation","local-partitioner"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}