{"record":{"id":"8b84c880dc20bdd7","repo":"apache/cassandra","slug":"unable-to-create-instance-of-generator-of-class-s","errorCode":null,"errorMessage":"Unable to create instance of generator of class %s: %s","messagePattern":"Unable to create instance of generator of class (.+?): (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/guardrails/ValueGenerator.java","lineNumber":167,"sourceCode":"            Class<? extends ValueGenerator<VALUE>> generatorClass =\n                (Class<? extends ValueGenerator<VALUE>>) rawGeneratorClass;\n\n            @SuppressWarnings(\"unchecked\")\n            ValueGenerator<VALUE> generator = generatorClass.getConstructor(CustomGuardrailConfig.class)\n                                                            .newInstance(config);\n            logger.debug(\"Using {} generator for guardrail '{}' with parameters {}\",\n                         generator.getClass(), name, generator.getParameters());\n            return generator;\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 generator of class %s: %s\",\n                                                    className, message), ex);\n        }\n    }\n}\n","sourceCodeStart":149,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/guardrails/ValueGenerator.java#L149-L172","documentation":"Cassandra guardrails can be configured with a custom generator class that generates values (e.g. passwords, role names). When instantiating the configured generator class fails (class missing, no public constructor, constructor throws, or class is not a ValueGenerator subtype), ValueGenerator.getGenerator wraps the reflective-instantiation failure in a ConfigurationException with this message.","triggerScenarios":"Configuring a guardrail such as password_policy or role_name_policy with a generator class that cannot be instantiated: the class is not on the classpath, has no no-arg public constructor, its constructor throws, or it does not extend ValueGenerator.","commonSituations":"Typo in the fully-qualified class name in cassandra.yaml; custom generator JAR missing from the lib directory; generator class written for a different Cassandra version or with a constructor taking arguments; ConfigurationException raised inside the generator's own initialization.","solutions":["Verify the configured class name is a correct, fully-qualified name of a class that extends org.apache.cassandra.db.guardrails.ValueGenerator","Ensure the class (and any JAR containing it) is on Cassandra's classpath (lib/ or a JRE-specific lib dir)","Give the generator a public no-argument constructor","Fix the root cause reported in the nested message (the message field carries ex.getCause().getMessage() when the cause is a ConfigurationException)","Test instantiation in a unit test before deploying, e.g. ValueGenerator.getGenerator(name, config)"],"exampleFix":"// before (cassandra.yaml)\npassword_policy_generator: com.example.MyPasswordGenerator2  // typo, class not found\n// after\npassword_policy_generator: com.example.MyPasswordGenerator  // class exists, public no-arg ctor, extends ValueGenerator","handlingStrategy":"validation","validationCode":"String cls = config.password_policy_generator;\nif (cls != null && !cls.isBlank()) {\n    try {\n        Class<?> c = Class.forName(cls.trim());\n        if (!org.apache.cassandra.db.guardrails.ValueGenerator.class.isAssignableFrom(c))\n            throw new IllegalArgumentException(cls + \" is not a ValueGenerator\");\n        c.getDeclaredConstructor().setAccessible(true); // throws if no no-arg ctor\n    } catch (ReflectiveOperationException e) {\n        throw new IllegalArgumentException(\"Cannot load generator \" + cls + \": \" + e, e);\n    }\n}","typeGuard":"boolean isValidGenerator(String name) {\n    try { return ValueGenerator.class.isAssignableFrom(Class.forName(name)); }\n    catch (Throwable t) { return false; }\n}","tryCatchPattern":"try {\n    generator = ValueGenerator.getGenerator(\"password_policy\", config);\n} catch (ConfigurationException e) {\n    logger.error(\"Bad generator config: {}\", e.getMessage());\n    generator = NoOpGenerator.INSTANCE;\n}","preventionTips":["Keep guardrail class names in a config file reviewed like code — a typo here fails at startup or first use","Ship custom generator JARs with the node and include them in deployment checklists","Always provide a public no-arg constructor on custom generators","Unit-test ValueGenerator.getGenerator with your cassandra.yaml before deploying"],"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"}