{"record":{"id":"b0512a91644b2fc6","repo":"apache/cassandra","slug":"s-function-resource-has-no-function-name","errorCode":null,"errorMessage":"%s function resource has no function name","messagePattern":"(.+?) function resource has no function name","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/auth/FunctionResource.java","lineNumber":250,"sourceCode":"    /**\n     * Get the name of the keyspace this resource relates to. In the case of the\n     * global root resource, return null\n     *\n     * @return the keyspace name of this resource, or null for the root resource\n     */\n    public String getKeyspace()\n    {\n        return keyspace;\n    }\n\n    /**\n     * @return a qualified FunctionName instance for a function-level resource.\n     * Throws IllegalStateException if called on the resource which doens't represent a single function.\n     */\n    public FunctionName getFunctionName()\n    {\n        if (level != Level.FUNCTION)\n            throw new IllegalStateException(String.format(\"%s function resource has no function name\", level));\n        return new FunctionName(keyspace, name);\n    }\n\n    /**\n     * @return Parent of the resource, if any. Throws IllegalStateException if it's the root-level resource.\n     */\n    public IResource getParent()\n    {\n        switch (level)\n        {\n            case KEYSPACE:\n                return root();\n            case FUNCTION:\n                return keyspace(keyspace);\n        }\n        throw new IllegalStateException(\"Root-level resource can't have a parent\");\n    }\n","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/auth/FunctionResource.java#L232-L268","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check resource.level == FunctionResource.Level.FUNCTION (or use the level accessor) before calling getFunctionName","Handle root/keyspace-level resources with their own accessors (getName/getKeyspace)","When constructing the resource, ensure it was built with FunctionResource.function(...) not keyspace(...)"],"exampleFix":"// before\nFunctionName fn = resource.getFunctionName();\n// after\nif (resource.getLevel() == FunctionResource.Level.FUNCTION)\n    FunctionName fn = resource.getFunctionName();","handlingStrategy":"type-guard","validationCode":"boolean isFunctionLevel(FunctionResource r) { return r.getLevel() == FunctionResource.Level.FUNCTION; }","typeGuard":"FunctionName asFunctionName(FunctionResource r) { return r.getLevel() == FunctionResource.Level.FUNCTION ? r.getFunctionName() : null; }","tryCatchPattern":"try { return r.getFunctionName(); } catch (IllegalStateException e) { return null; /* not a function-level resource */ }","preventionTips":["Check the level before accessing level-specific accessors","Handle root/keyspace resources with their dedicated accessors","Remember resources obtained from permission listings may be any level"],"tags":["cassandra","auth","illegal-state","resource-level"],"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"}