{"record":{"id":"91e00520741d2212","repo":"apache/cassandra","slug":"failed-to-create-instance-of","errorCode":null,"errorMessage":"Failed to create instance of ","messagePattern":"Failed to create instance of ","errorType":"exception","errorClass":"CommandLine.InitializationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/NodeTool.java","lineNumber":356,"sourceCode":"                        else if (field.getType().equals(Output.class))\n                        {\n                            field.setAccessible(true);\n                            field.set(bean, output);\n                        }\n                        else\n                        {\n                            throw new RuntimeException(\"Unsupported injectable field type: \" + field.getType() +\n                                    \" in class \" + beanClass.getName() + \". \" +\n                                    \"Only INodeProbeFactory and Output are supported.\");\n                        }\n                    }\n                }\n                while ((beanClass = beanClass.getSuperclass()) != null);\n                return bean;\n            }\n            catch (Exception e)\n            {\n                throw new CommandLine.InitializationException(\"Failed to create instance of \" + cls, e);\n            }\n        }\n    }\n}\n","sourceCodeStart":338,"sourceCodeEnd":361,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/NodeTool.java#L338-L361","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npublic MyCommand(String configPath) { ... }\n// after\npublic MyCommand() { }\nvoid execute() { String configPath = parseArgs(); ... }","handlingStrategy":"try-catch","validationCode":"// ensure a public no-arg constructor exists\nif (java.lang.reflect.Modifier.isPublic(cls.getModifiers())\n    && java.util.Arrays.stream(cls.getConstructors()).noneMatch(c -> c.getParameterCount() == 0))\n    throw new IllegalStateException(cls + \" needs a public no-arg constructor\");","typeGuard":null,"tryCatchPattern":"try { CommandLine cmd = factory.create(CommandClass.class); ... }\ncatch (CommandLine.InitializationException e) {\n    LOG.error(\"Cannot init command \" + e.getMessage() + \": \" + e.getCause(), e);\n}","preventionTips":["Always give command classes public no-arg constructors","Keep constructors side-effect free; defer work to execute()","Inspect the wrapped cause when diagnosing"],"tags":["nodetool","reflection","picocli","initialization","cassandra"],"backgroundTag":"module-init-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}