apache/cassandra · error · ConfigurationException
Unable to create instance of generator of class
Error message
Unable to create instance of generator of class %s: %s
What it means
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.
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)
Example fix
// before (cassandra.yaml) password_policy_generator: com.example.MyPasswordGenerator2 // typo, class not found // after password_policy_generator: com.example.MyPasswordGenerator // class exists, public no-arg ctor, extends ValueGenerator
Defensive patterns
Strategy: validation
Validate before calling
String cls = config.password_policy_generator;
if (cls != null && !cls.isBlank()) {
try {
Class<?> c = Class.forName(cls.trim());
if (!org.apache.cassandra.db.guardrails.ValueGenerator.class.isAssignableFrom(c))
throw new IllegalArgumentException(cls + " is not a ValueGenerator");
c.getDeclaredConstructor().setAccessible(true); // throws if no no-arg ctor
} catch (ReflectiveOperationException e) {
throw new IllegalArgumentException("Cannot load generator " + cls + ": " + e, e);
}
} Type guard
boolean isValidGenerator(String name) {
try { return ValueGenerator.class.isAssignableFrom(Class.forName(name)); }
catch (Throwable t) { return false; }
} Try / catch
try {
generator = ValueGenerator.getGenerator("password_policy", config);
} catch (ConfigurationException e) {
logger.error("Bad generator config: {}", e.getMessage());
generator = NoOpGenerator.INSTANCE;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Unable to create instance of validator of class
- Cannot find configured row cache provider class
- couldn't load cipher factory
- default_keyspace_rf to be set
- default_keyspace_rf to be set
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/8b84c880dc20bdd7.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/guardrails/ValueGenerator.java:167
Class<? extends ValueGenerator<VALUE>> generatorClass =
(Class<? extends ValueGenerator<VALUE>>) rawGeneratorClass;
@SuppressWarnings("unchecked")
ValueGenerator<VALUE> generator = generatorClass.getConstructor(CustomGuardrailConfig.class)
.newInstance(config);
logger.debug("Using {} generator for guardrail '{}' with parameters {}",
generator.getClass(), name, generator.getParameters());
return generator;
}
catch (Exception ex)
{
String message;
if (ex.getCause() instanceof ConfigurationException)
message = ex.getCause().getMessage();
else
message = ex.getMessage();
throw new ConfigurationException(format("Unable to create instance of generator of class %s: %s",
className, message), ex);
}
}
}
View on GitHub (pinned to 88fd0f6a0e)