apache/cassandra · error · CommandLine.InitializationException
Failed to create instance of
Error message
Failed to create instance of
What it means
NodeTool's factory wraps any exception encountered while reflectively constructing and wiring a command bean (instantiating the class, setting injectable fields) into picocli's CommandLine.InitializationException with the class name as the message. It is a catch-all for reflection failures during command initialization.
Source
Thrown at src/java/org/apache/cassandra/tools/NodeTool.java:356
else if (field.getType().equals(Output.class))
{
field.setAccessible(true);
field.set(bean, output);
}
else
{
throw new RuntimeException("Unsupported injectable field type: " + field.getType() +
" in class " + beanClass.getName() + ". " +
"Only INodeProbeFactory and Output are supported.");
}
}
}
while ((beanClass = beanClass.getSuperclass()) != null);
return bean;
}
catch (Exception e)
{
throw new CommandLine.InitializationException("Failed to create instance of " + cls, e);
}
}
}
}
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Give the command class a public no-argument constructor
- Fix the root cause exception (it is attached as the cause — inspect the stack trace)
- Ensure constructor/injection code does not throw at construction time; defer work to execute()
- Verify the command class and its injectable fields follow NodeTool's supported types
Example fix
// before
public MyCommand(String configPath) { ... }
// after
public MyCommand() { }
void execute() { String configPath = parseArgs(); ... } Defensive patterns
Strategy: try-catch
Validate before calling
// ensure a public no-arg constructor exists
if (java.lang.reflect.Modifier.isPublic(cls.getModifiers())
&& java.util.Arrays.stream(cls.getConstructors()).noneMatch(c -> c.getParameterCount() == 0))
throw new IllegalStateException(cls + " needs a public no-arg constructor"); Try / catch
try { CommandLine cmd = factory.create(CommandClass.class); ... }
catch (CommandLine.InitializationException e) {
LOG.error("Cannot init command " + e.getMessage() + ": " + e.getCause(), e);
} Prevention
- Always give command classes public no-arg constructors
- Keep constructors side-effect free; defer work to execute()
- Inspect the wrapped cause when diagnosing
When it happens
Trigger: Any exception while creating a NodeTool command instance: the command class has no accessible no-arg constructor, its constructor throws, an @Inject field is inaccessible/fails on set, or the unsupported-type RuntimeException from create() bubbles up here.
Common situations: Custom nodetool command with a constructor taking arguments; constructor code that throws (e.g. reading config at construction); obfuscation or module restrictions blocking setAccessible; the unsupported-injectable-type error being wrapped.
Related errors
- Failed to initialize command line hierarchy
- Unsupported injectable field type: in class . Only INodePro
- Invalid comparator class %s: must define a public static ins
- Properties specified %s are not understood by %s
- %s.validateOptions() threw an error: %s %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/91e00520741d2212.
Report an issue: GitHub.