{"record":{"id":"be9005f2c3574b00","repo":"apache/cassandra","slug":"setup-must-be-called-first-for-cassandradaemon","errorCode":null,"errorMessage":"setup() must be called first for CassandraDaemon","messagePattern":"setup\\(\\) must be called first for CassandraDaemon","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/CassandraDaemon.java","lineNumber":943,"sourceCode":"\n            // This node has not joined the ring (i.e. it was started with -Dcassandra.join_ring=false)\n            if (StorageService.instance.isStarting())\n                return;\n\n            if (!SystemKeyspace.bootstrapComplete())\n            {\n                throw new IllegalStateException(\"Node is not yet bootstrapped completely. Use nodetool to check bootstrap\" +\n                                                \" state and resume. For more, see `nodetool help bootstrap`\");\n            }\n        }\n    }\n\n    public void startNativeTransport()\n    {\n        validateTransportsCanStart();\n\n        if (nativeTransportService == null)\n            throw new IllegalStateException(\"setup() must be called first for CassandraDaemon\");\n\n        // this iterates over a collection of servers and returns true if one of them is started\n        boolean alreadyRunning = nativeTransportService.isRunning();\n\n        // this might in practice start all servers which are not started yet\n        nativeTransportService.start();\n\n        // interact with gossip only in case if no server was started before to signal they are started now\n        if (!alreadyRunning)\n            StorageService.instance.setRpcReady(true);\n    }\n\n    @Deprecated(since = \"5.0.0\")\n    public void stopNativeTransport()\n    {\n        stopNativeTransport(false);\n    }\n","sourceCodeStart":925,"sourceCodeEnd":961,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/CassandraDaemon.java#L925-L961","documentation":"startNativeTransport requires that CassandraDaemon.setup() has already run and initialized nativeTransportService; if setup() was skipped or failed before the transport service was created, calling startNativeTransport throws this IllegalStateException. The field is null because the native transport service is only constructed during setup.","triggerScenarios":"Invoking CassandraDaemon.startNativeTransport() (directly or via startClientTransports) on a CassandraDaemon instance where setup() was never called, or where setup failed before initializing the native transport service.","commonSituations":"Embedded/testing harnesses that construct CassandraDaemon manually and call startNativeTransport before completing the daemon lifecycle; setup() aborted early due to a config error so nativeTransportService remained null.","solutions":["Call cassandraDaemon.setup() (or the full initialize()/start() lifecycle) before invoking startNativeTransport().","Fix the underlying setup() failure so nativeTransportService is initialized rather than working around the null.","If only transports should be (re)started, call start() which internally validates and starts the initialized services."],"exampleFix":"// before\nCassandraDaemon daemon = new CassandraDaemon();\ndaemon.startNativeTransport();\n// after\nCassandraDaemon daemon = new CassandraDaemon();\ndaemon.setup();\ndaemon.startNativeTransport();","handlingStrategy":"try-catch","validationCode":"if (daemon instanceof CassandraDaemon && !isSetupComplete(daemon))\n    daemon.setup();","typeGuard":null,"tryCatchPattern":"try { daemon.startNativeTransport(); } catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"setup() must be called first\")) { daemon.setup(); daemon.startNativeTransport(); }\n}","preventionTips":["Always run the full lifecycle setup() -> initialize() -> start() in embedded usage","Never hand-construct CassandraDaemon and call transport methods directly","Check logs for setup() failures — the null service usually means setup aborted early"],"tags":["cassandra","lifecycle","native-transport"],"backgroundTag":"invalid-state-transition","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"}