{"record":{"id":"c97852a1a4e0b511","repo":"apache/cassandra","slug":"name-s-is-not-valid-for-any-resource-type","errorCode":null,"errorMessage":"Name %s is not valid for any resource type","messagePattern":"Name (.+?) is not valid for any resource type","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/auth/Resources.java","lineNumber":78,"sourceCode":"    /**\n     * Creates an IResource instance from its external name.\n     * Resource implementation class is inferred by matching against the known IResource\n     * impls' root level resources.\n     * @param name external name to create IResource from\n     * @return an IResource instance created from the name\n     */\n    public static IResource fromName(String name)\n    {\n        if (name.startsWith(RoleResource.root().getName()))\n            return RoleResource.fromName(name);\n        else if (name.startsWith(DataResource.root().getName()))\n            return DataResource.fromName(name);\n        else if (name.startsWith(FunctionResource.root().getName()))\n            return FunctionResource.fromName(name);\n        else if (name.startsWith(JMXResource.root().getName()))\n            return JMXResource.fromName(name);\n        else\n            throw new IllegalArgumentException(String.format(\"Name %s is not valid for any resource type\", name));\n    }\n}\n","sourceCodeStart":60,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/auth/Resources.java#L60-L81","documentation":"Resources.fromName() maps a resource name string to the correct IResource (DataResource, FunctionResource, JMXResource, etc.) by prefix-matching against each type's root name. If no known root prefix matches, the name is not a valid resource of any type and IllegalArgumentException is thrown.","triggerScenarios":"GRANT/REVOKE/LIST PERMISSIONS with a misspelled or malformed resource name, e.g. GRANT SELECT ON 'keyspace1' (missing data/ or <keyspace> prefix form), or a name for a resource type that doesn't exist.","commonSituations":"Hand-written CQL permission grants with wrong quoting/prefixes; automation generating resource names that don't match the documented formats like data/ks, functions/ks, jmx; copy-pasted names from different Cassandra versions.","solutions":["Use the documented resource syntax: data/<keyspace>[/<table>], <keyspace>.<function>[args], jmx/<mbean>, all-keyspaces, roles, etc.","Quote the resource name properly in CQL, e.g. GRANT SELECT ON KEYSPACE my_ks TO role_name","Validate the prefix with the target type's root (e.g. DataResource.root().getName()) before calling fromName"],"exampleFix":"// before\nGRANT SELECT ON 'keyspace1' TO reader;   -- invalid name\n// after\nGRANT SELECT ON KEYSPACE keyspace1 TO reader;","handlingStrategy":"try-catch","validationCode":"boolean ok = name.startsWith(\"data/\") || name.startsWith(\"functions/\") || name.startsWith(\"jmx/\") || name.equals(\"<all-keyspaces>\") || name.matches(\"[a-zA-Z0-9_]+\\\\.[a-zA-Z0-9_]+(\\\\[.*\\\\])?\");","typeGuard":"boolean isWellFormedResourceName(String name) { return DATA_ROOTS.stream().anyMatch(name::startsWith); }","tryCatchPattern":"try { grant(resource, role); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"not valid for any resource type\")) printValidResourceFormats(); }","preventionTips":["Generate resource names from the type classes' getName()/root() APIs, not string literals","Test GRANT/REVOKE statements against a dev cluster first","Keep an allowlist of valid resource name patterns in automation"],"tags":["authorization","resources","invalid-name"],"backgroundTag":"invalid-argument-value","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"}