{"record":{"id":"2b3b317e252f329d","repo":"apache/cassandra","slug":"unable-to-serialize-role-name-policy-configuration","errorCode":null,"errorMessage":"Unable to serialize role_name_policy configuration","messagePattern":"Unable to serialize role_name_policy configuration","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/guardrails/Guardrails.java","lineNumber":1600,"sourceCode":"        {\n            return JsonUtils.JSON_OBJECT_MAPPER.writeValueAsString(passwordPolicy.getConfig());\n        }\n        catch (Throwable t)\n        {\n            throw new RuntimeException(\"Unable to serialize password_policy configuration\");\n        }\n    }\n\n    @Override\n    public String getRoleNamePolicy()\n    {\n        try\n        {\n            return JsonUtils.JSON_OBJECT_MAPPER.writeValueAsString(roleNamePolicy.getConfig());\n        }\n        catch (Throwable t)\n        {\n            throw new RuntimeException(\"Unable to serialize role_name_policy configuration\");\n        }\n    }\n\n    @Override\n    public void setPasswordPolicy(String value)\n    {\n        try\n        {\n            passwordPolicy.reconfigure(JsonUtils.JSON_OBJECT_MAPPER.readValue(value, new TypeReference<>() {}));\n        }\n        catch (Throwable t)\n        {\n            throw new RuntimeException(t);\n        }\n    }\n\n    @Override\n    public void setRoleNamePolicy(String value)","sourceCodeStart":1582,"sourceCodeEnd":1618,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/guardrails/Guardrails.java#L1582-L1618","documentation":"Identical mechanism to the password_policy variant: serializing the role name policy configuration to JSON fails, and Guardrails.getRoleNamePolicy() throws RuntimeException('Unable to serialize role_name_policy configuration') with the underlying cause dropped.","triggerScenarios":"Calling getRoleNamePolicy() after the role name policy config object became non-serializable by Jackson (bad object set via setRoleNamePolicy, missing accessors, Jackson version conflict).","commonSituations":"Programmatic administration tools reading back a recently changed role_name_policy; mixed Jackson versions on the classpath; a policy object with throwing getters.","solutions":["Reproduce to expose the hidden Jackson cause (the message omits it); check server logs","Reset role_name_policy to the default via the corresponding setter and retry","Align Jackson versions / remove conflicting jackson-databind jars from the classpath","Fix the config object's getters so JSON serialization succeeds"],"exampleFix":"// before\nRoleNamePolicyConfig with a getter that throws -> serialization fails\n// after\nMake all getters side-effect-free and Jackson-visible (public accessors, no throwing getters)","handlingStrategy":"try-catch","validationCode":"// Round-trip check after setting the policy\nString json = guardrails.getRoleNamePolicy();\nif (json == null || json.isEmpty()) logger.warn(\"role_name_policy serialization returned empty\");","typeGuard":null,"tryCatchPattern":"try {\n    String json = guardrails.getRoleNamePolicy();\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"role_name_policy\")) {\n        logger.error(\"Role name policy not serializable; resetting\", e);\n        guardrails.setRoleNamePolicy(defaultJson);\n    }\n}","preventionTips":["Validate JSON policy input before calling the setter","Avoid custom config classes with throwing or inaccessible getters","Keep classpath clean of mismatched jackson-databind versions"],"tags":["guardrails","json-serialization","role-name-policy"],"backgroundTag":"json-serialization-failed","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"}