{"record":{"id":"5aa24dfba67f9dfa","repo":"apache/cassandra","slug":"unable-to-create-instance-of-validator-of-class-s","errorCode":null,"errorMessage":"Unable to create instance of validator of class %s: %s","messagePattern":"Unable to create instance of validator of class (.+?): (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/guardrails/ValueValidator.java","lineNumber":151,"sourceCode":"            Class<? extends ValueValidator<VALUE>> validatorClass =\n                (Class<? extends ValueValidator<VALUE>>) rawValidatorClass;\n\n            @SuppressWarnings(\"unchecked\")\n            ValueValidator<VALUE> validator = validatorClass.getConstructor(CustomGuardrailConfig.class)\n                                                            .newInstance(config);\n            logger.debug(\"Using {} validator for guardrail '{}' with parameters {}\",\n                         validator.getClass(), name, validator.getParameters());\n            return validator;\n        }\n        catch (Exception ex)\n        {\n            String message;\n            if (ex.getCause() instanceof ConfigurationException)\n                message = ex.getCause().getMessage();\n            else\n                message = ex.getMessage();\n\n            throw new ConfigurationException(format(\"Unable to create instance of validator of class %s: %s\",\n                                                    className, message), ex);\n        }\n    }\n}\n","sourceCodeStart":133,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/guardrails/ValueValidator.java#L133-L156","documentation":"Cassandra guardrails support a custom validator class that validates generated/configured values. ValueValidator.getValidator reflectively instantiates the class configured for a guardrail (e.g. password_policy_validator); when that fails — missing class, missing public no-arg constructor, constructor throwing, wrong type — it wraps the failure in a ConfigurationException with this message.","triggerScenarios":"Setting a guardrail validator option to a class name that cannot be reflectively instantiated at startup or when the guardrail is first used.","commonSituations":"Misspelled fully-qualified class name in cassandra.yaml; validator JAR not deployed to lib/; validator class has a parameterized constructor; class was compiled against an incompatible Cassandra version; nested ConfigurationException from the validator's static/instance init.","solutions":["Check that the configured value is the correct fully-qualified class name of a ValueValidator subclass","Deploy the validator class/JAR to Cassandra's classpath","Add a public no-arg constructor to the validator class","Read the nested message in the exception — ConfigurationException causes are unwrapped into the message","Run ValueValidator.getValidator(name, config) in a unit test before rollout"],"exampleFix":"// before\nrole_name_policy_validator: com.example.RoleNameValidator  // ctor takes args\n// after\npublic class RoleNameValidator extends ValueValidator<String> { public RoleNameValidator() {} ... }","handlingStrategy":"validation","validationCode":"String cls = config.password_policy_validator;\nif (cls != null && !cls.isBlank()) {\n    try {\n        Class<?> c = Class.forName(cls.trim());\n        if (!org.apache.cassandra.db.guardrails.ValueValidator.class.isAssignableFrom(c))\n            throw new IllegalArgumentException(cls + \" is not a ValueValidator\");\n        c.getDeclaredConstructor();\n    } catch (ReflectiveOperationException e) {\n        throw new IllegalArgumentException(\"Cannot load validator \" + cls + \": \" + e, e);\n    }\n}","typeGuard":"boolean isValidValidator(String name) {\n    try { return ValueValidator.class.isAssignableFrom(Class.forName(name)); }\n    catch (Throwable t) { return false; }\n}","tryCatchPattern":"try {\n    validator = ValueValidator.getValidator(\"password_policy\", config);\n} catch (ConfigurationException e) {\n    logger.error(\"Invalid validator class: {}\", e.getMessage());\n    validator = NoOpValidator.INSTANCE;\n}","preventionTips":["Test-load configured validator classes in CI with the same classpath as production","Keep custom validators in a dedicated JAR versioned with your Cassandra version","Prefer built-in validators unless customization is required","Read the nested ConfigurationException message first — it names the actual init failure"],"tags":["guardrails","configuration","reflection"],"backgroundTag":"invalid-config-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"}