{"record":{"id":"aca846081c6dedeb","repo":"apache/cassandra","slug":"cannot-specify-tokens-without-keyspace","errorCode":null,"errorMessage":"Cannot specify tokens without keyspace.","messagePattern":"Cannot specify tokens without keyspace\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/Rebuild.java","lineNumber":100,"sourceCode":"\n        if (sourceDc != null)\n        {\n            if (sourceDc.equals(DatabaseDescriptor.getLocalDataCenter()) && excludeLocalDatacenterNodes) // fail if source DC is local and --exclude-local-dc is set\n                throw new IllegalArgumentException(\"Cannot set source data center to be local data center, when excludeLocalDataCenter flag is set\");\n            Set<String> availableDCs = ClusterMetadata.current().directory.knownDatacenters();\n            if (!availableDCs.contains(sourceDc))\n            {\n                throw new IllegalArgumentException(String.format(\"Provided datacenter '%s' is not a valid datacenter, available datacenters are: %s\",\n                                                                 sourceDc, String.join(\",\", availableDCs)));\n            }\n        }\n\n        try\n        {\n            // check the arguments\n            if (keyspace == null && tokens != null)\n            {\n                throw new IllegalArgumentException(\"Cannot specify tokens without keyspace.\");\n            }\n\n            logger.info(\"rebuild from dc: {}, {}, {}\", sourceDc == null ? \"(any dc)\" : sourceDc,\n                        keyspace == null ? \"(All keyspaces)\" : keyspace,\n                        tokens == null ? \"(All tokens)\" : tokens);\n\n            StorageService.instance.repairPaxosForTopologyChange(\"rebuild\");\n            ClusterMetadata metadata = ClusterMetadata.current();\n            MovementMap rebuildMovements = movementMap(metadata, keyspace, tokens);\n            logger.info(\"Rebuild movements: {}\", rebuildMovements);\n            RangeStreamer streamer = new RangeStreamer(metadata,\n                                                       StreamOperation.REBUILD,\n                                                       false, // no strict consistency when rebuilding\n                                                       DatabaseDescriptor.getNodeProximity(),\n                                                       StorageService.instance.streamStateStore,\n                                                       false,\n                                                       DatabaseDescriptor.getStreamingConnectionsPerHost(),\n                                                       rebuildMovements,","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/Rebuild.java#L82-L118","documentation":"IllegalArgumentException from Rebuild.rebuild when nodetool rebuild is invoked with --tokens (or an equivalent token list) but no keyspace argument. Token-streaming rebuild is only meaningful in a keyspace context, so this argument combination is rejected up front before any streaming starts.","triggerScenarios":"Calling rebuild(sourceDc, keyspace=null, tokens=<list>, ...) — e.g. `nodetool rebuild --initial-token ...` style usage without specifying -ks.","commonSituations":"Operator wants to rebuild only certain ranges after bootstrap issue but forgets the keyspace flag; scripting the JMX rebuild(String,String,String,String,boolean) with null keyspace but non-null tokens.","solutions":["Supply the keyspace the tokens belong to along with tokens","Drop the tokens argument to rebuild all keyspaces/ranges"],"exampleFix":"// before\nnodetool rebuild --tokens \"(-9223372036854775808,-4611686018427387904]\"\n// after\nnodetool rebuild -ks my_keyspace --tokens \"(-9223372036854775808,-4611686018427387904]\"","handlingStrategy":"validation","validationCode":"if (tokens != null && keyspace == null)\n    throw new IllegalArgumentException(\"tokens requires keyspace\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass -ks when using --tokens with `nodetool rebuild`","Validate CLI/script arguments before invoking the JMX rebuild method","Keep runbook commands with both flags together to avoid omissions"],"tags":["validation","arguments","rebuild"],"backgroundTag":"missing-required-argument","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"}