{"record":{"id":"bf3632ff88de6121","repo":"apache/cassandra","slug":"cannot-specify-tokens-without-keyspace-bf3632","errorCode":null,"errorMessage":"Cannot specify tokens without keyspace.","messagePattern":"Cannot specify tokens without keyspace\\.","errorType":"console","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/Rebuild.java","lineNumber":61,"sourceCode":"    private String tokens = null;\n\n    @Option(paramLabel = \"specific_sources\",\n            names = {\"-s\", \"--sources\"},\n            description = \"Use -s to specify hosts that this node should stream from when -ts is used. Multiple hosts should be separated using commas (e.g. 127.0.0.1,127.0.0.2,...)\")\n    private String specificSources = null;\n\n    @Option(paramLabel = \"exclude_local_dc\",\n            names = {\"--exclude-local-dc\"},\n            description = \"Use --exclude-local-dc to exclude nodes in local data center as source for streaming.\")\n    private boolean excludeLocalDatacenterNodes = false;\n\n    @Override\n    public void execute(NodeProbe probe)\n    {\n        // check the arguments\n        if (keyspace == null && tokens != null)\n        {\n            throw new IllegalArgumentException(\"Cannot specify tokens without keyspace.\");\n        }\n\n        probe.rebuild(sourceDataCenterName, keyspace, tokens, specificSources, excludeLocalDatacenterNodes);\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/Rebuild.java#L43-L67","documentation":"Nodetool 'rebuild' only accepts the --tokens (source-token selection) option together with an explicit keyspace; tokens filter which sources stream data for a specific keyspace rebuild. Passing --tokens with no keyspace is rejected client-side with this IllegalArgumentException before the JMX rebuild call.","triggerScenarios":"`nodetool rebuild -- --tokens <token,...>` (or -tk) without specifying a keyspace.","commonSituations":"Copying rebuild examples that use --tokens without noticing they also pass a keyspace; scripting a full-cluster rebuild where keyspace was omitted intentionally.","solutions":["Add the keyspace: `nodetool rebuild -- <keyspace> -- --tokens <tokens>`","Drop the --tokens option if you intend a full (all-keyspace) rebuild","Run `nodetool help rebuild` to confirm argument syntax"],"exampleFix":"// before\nnodetool rebuild -- --tokens 1,2,3\n// after\nnodetool rebuild -- myks -- --tokens 1,2,3","handlingStrategy":"validation","validationCode":"if [ -n \"$TOKENS\" ] && [ -z \"$KEYSPACE\" ]; then echo \"--tokens requires a keyspace\"; exit 2; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair --tokens with an explicit keyspace in scripts","Drop --tokens for full rebuilds","Validate CLI flags in wrapper scripts"],"tags":["nodetool","cli","argument-validation","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-17T15:17:12.973Z"}