apache/cassandra · error · IllegalStateException

%s function resource has no function name

Error message

%s function resource has no function name

What it means

FunctionResource.getFunctionName is only valid on a FUNCTION-level resource (a single specific function). Calling it on the root ('functions') or keyspace-level ('functions/<ks>') resource throws IllegalStateException because there is no single function name to return.

Source

Thrown at src/java/org/apache/cassandra/auth/FunctionResource.java:250

    /**
     * Get the name of the keyspace this resource relates to. In the case of the
     * global root resource, return null
     *
     * @return the keyspace name of this resource, or null for the root resource
     */
    public String getKeyspace()
    {
        return keyspace;
    }

    /**
     * @return a qualified FunctionName instance for a function-level resource.
     * Throws IllegalStateException if called on the resource which doens't represent a single function.
     */
    public FunctionName getFunctionName()
    {
        if (level != Level.FUNCTION)
            throw new IllegalStateException(String.format("%s function resource has no function name", level));
        return new FunctionName(keyspace, name);
    }

    /**
     * @return Parent of the resource, if any. Throws IllegalStateException if it's the root-level resource.
     */
    public IResource getParent()
    {
        switch (level)
        {
            case KEYSPACE:
                return root();
            case FUNCTION:
                return keyspace(keyspace);
        }
        throw new IllegalStateException("Root-level resource can't have a parent");
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Check resource.level == FunctionResource.Level.FUNCTION (or use the level accessor) before calling getFunctionName
  2. Handle root/keyspace-level resources with their own accessors (getName/getKeyspace)
  3. When constructing the resource, ensure it was built with FunctionResource.function(...) not keyspace(...)

Example fix

// before
FunctionName fn = resource.getFunctionName();
// after
if (resource.getLevel() == FunctionResource.Level.FUNCTION)
    FunctionName fn = resource.getFunctionName();
Defensive patterns

Strategy: type-guard

Validate before calling

boolean isFunctionLevel(FunctionResource r) { return r.getLevel() == FunctionResource.Level.FUNCTION; }

Type guard

FunctionName asFunctionName(FunctionResource r) { return r.getLevel() == FunctionResource.Level.FUNCTION ? r.getFunctionName() : null; }

Try / catch

try { return r.getFunctionName(); } catch (IllegalStateException e) { return null; /* not a function-level resource */ }

Prevention

When it happens

Trigger: Calling getFunctionName() on FunctionResource.root() or FunctionResource.keyspace(ks); code that receives a FunctionResource of unknown level (e.g. from LIST PERMISSIONS results or a permission set) and assumes it is function-level.

Common situations: Iterating over all resources a role holds and calling getFunctionName on every one without checking the level; refactoring that changed the resource level passed to a helper.

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/b0512a91644b2fc6. Report an issue: GitHub.