{"record":{"id":"0f35bcbb8263edd2","repo":"apache/cassandra","slug":"s-s-keyspace-name-must-not-be-empty","errorCode":null,"errorMessage":"%s.%s: Keyspace name must not be empty","messagePattern":"(.+?)\\.(.+?): Keyspace name must not be empty","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/schema/TableMetadata.java","lineNumber":1012,"sourceCode":"        private boolean assignUniqueIds = false;\n\n        private Builder(String keyspace, String name, TableId id)\n        {\n            this.keyspace = keyspace;\n            this.name = name;\n            this.id = id;\n        }\n\n        private Builder(String keyspace, String name)\n        {\n            this.keyspace = keyspace;\n            this.name = name;\n        }\n\n        public TableMetadata build()\n        {\n            if (keyspace == null)\n                throw new ConfigurationException(keyspace + '.' + name + \": Keyspace name must not be empty\");\n            if (partitioner == null)\n                partitioner = DatabaseDescriptor.getPartitioner();\n\n            if (id == null)\n            {\n                // make sure vtables use deteriminstic ids so they can be referenced in calls cross-nodes\n                // see CASSANDRA-17295\n                if (kind == Kind.VIRTUAL)\n                    id = TableId.unsafeDeterministic(keyspace, name);\n                else\n                    id = TableId.generate();\n            }\n\n            if (assignUniqueIds)\n            {\n                int nextId = Math.max(0, maxAssignedUniqueId + 1);\n                for (int i = 0 ; i < partitionKeyColumns.size() ; ++i)\n                {","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/schema/TableMetadata.java#L994-L1030","documentation":"Thrown as a ConfigurationException by the TableMetadata.Builder when building a table without a keyspace set. A table definition is meaningless without its parent keyspace, so construction fails early rather than producing a broken TableMetadata.","triggerScenarios":"Calling TableMetadata.builder() ... build() without invoking builder().keyspace(ksName) — usually from programmatic schema construction (tools, tests, virtual table implementations).","commonSituations":"Programmatic table builders missing the keyspace() call; refactors that reorder builder calls and drop keyspace(); test fixtures constructing tables directly instead of via parsed DDL.","solutions":["Call keyspace(\"<name>\") on the builder before build()","Parse DDL through the schema statement machinery so keyspace is set from context","Assert builder state in helper methods that wrap table construction","Set a default keyspace in the utility that creates builders"],"exampleFix":"// before\nTableMetadata t = TableMetadata.builder().name(\"users\").addPartitionKeyColumn(\"id\", UUIDType.instance).build();\n// after\nTableMetadata t = TableMetadata.builder().keyspace(\"my_ks\").name(\"users\").addPartitionKeyColumn(\"id\", UUIDType.instance).build();","handlingStrategy":"type-guard","validationCode":"assert builder != null; // ensure keyspace was set: track it in a wrapper around TableMetadata.builder()","typeGuard":"TableMetadata.Builder requireKeyspace(TableMetadata.Builder b, String ks) { if (ks == null || ks.isEmpty()) throw new IllegalArgumentException(\"keyspace required\"); return b.keyspace(ks); }","tryCatchPattern":"try { TableMetadata t = builder.build(); ... } catch (ConfigurationException e) { throw new IllegalStateException(\"Table builder misconfigured: \" + e.getMessage(), e); }","preventionTips":["Wrap TableMetadata.builder() in a helper that mandates keyspace()","Construct tables via parsed DDL where possible","Add unit tests for programmatic table construction","Keep builder usage centralized in one factory"],"tags":["cassandra","schema","builder"],"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"}