apache/cassandra · error · IllegalStateException

ROOT data resource has no keyspace

Error message

ROOT data resource has no keyspace

What it means

DataResource.getKeyspace returns the keyspace component only for non-root resources (all-keyspaces/all-tables/table levels). Calling it on the ROOT resource is invalid — there is no keyspace — so it throws IllegalStateException.

Source

Thrown at src/java/org/apache/cassandra/auth/DataResource.java:221

        return level == Level.KEYSPACE;
    }

    public boolean isAllTablesLevel()
    {
        return level == Level.ALL_TABLES;
    }

    public boolean isTableLevel()
    {
        return level == Level.TABLE;
    }
    /**
     * @return keyspace of the resource. Throws IllegalStateException if it's the root-level resource.
     */
    public String getKeyspace()
    {
        if (isRootLevel())
            throw new IllegalStateException("ROOT data resource has no keyspace");
        return keyspace;
    }

    /**
     * @return column family of the resource. Throws IllegalStateException if it's not a table-level resource.
     */
    public String getTable()
    {
        if (!isTableLevel())
            throw new IllegalStateException(String.format("%s data resource has no table", level));
        return table;
    }

    /**
     * @return Whether or not the resource has a parent in the hierarchy.
     */
    public boolean hasParent()
    {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Check !resource.isRootLevel() (or level != Level.ROOT) before calling getKeyspace()
  2. Branch on resource level and handle ROOT separately
  3. If you need an optional keyspace, wrap with the level check and return null/Optional.empty for root

Example fix

// before
String ks = resource.getKeyspace();
// after
String ks = resource.isRootLevel() ? null : resource.getKeyspace();
Defensive patterns

Strategy: type-guard

Validate before calling

boolean hasKeyspace(DataResource r) { return !r.isRootLevel(); }

Type guard

String keyspaceOrNull(DataResource r) { return r.isRootLevel() ? null : r.getKeyspace(); }

Try / catch

try { ks = r.getKeyspace(); } catch (IllegalStateException e) { ks = null; /* r is ROOT */ }

Prevention

When it happens

Trigger: Calling getKeyspace() on DataResource.root(); generic permission-checking or logging code that extracts the keyspace from any DataResource without checking isRootLevel(); existing callers listed include maybeCorrectResource, validate, and keyspace().

Common situations: Functions that receive resources from LIST PERMISSIONS output spanning all levels and unconditionally call getKeyspace; refactoring where a ROOT case was not added to a switch.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/156128a977d7a82b. Report an issue: GitHub.