{"record":{"id":"8199ab8aa59a532e","repo":"apache/cassandra","slug":"no-jmxconnect-command-found-in-the-top-level-hiera","errorCode":null,"errorMessage":"No JmxConnect command found in the top-level hierarchy","messagePattern":"No JmxConnect command found in the top-level hierarchy","errorType":"console","errorClass":"InitializationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/JmxConnect.java","lineNumber":93,"sourceCode":"    @Option(names = { \"-pw\", \"--password\" }, description = \"Remote jmx agent password\", arity = \"0..1\")\n    private String password = EMPTY;\n\n    @Option(names = { \"-pwf\", \"--password-file\" }, description = \"Path to the JMX password file\", arity = \"0..1\")\n    private String passwordFilePath = EMPTY;\n\n    @Inject\n    private INodeProbeFactory nodeProbeFactory;\n\n    /**\n     * This method is called by picocli and used depending on the execution strategy.\n     * @param parseResult The parsed command line.\n     * @return The exit code.\n     */\n    public static int executionStrategy(ParseResult parseResult)\n    {\n        CommandSpec jmx = parseResult.commandSpec().mixins().get(MIXIN_KEY);\n        if (jmx == null)\n            throw new InitializationException(\"No JmxConnect command found in the top-level hierarchy\");\n\n        try (JmxConnectionCommandInvoker invoker = new JmxConnectionCommandInvoker((JmxConnect) jmx.userObject()))\n        {\n            return invoker.execute(parseResult);\n        }\n        catch (JmxConnectionCommandInvoker.CloseException e)\n        {\n            jmx.commandLine()\n               .getErr()\n               .println(\"Failed to connect to JMX: \" + e.getMessage());\n            return jmx.commandLine().getExitCodeExceptionMapper().getExitCode(e);\n        }\n    }\n\n    /**\n     * Initialize the JMX connection to the Cassandra node using the provided options.\n     */\n    @Override","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/JmxConnect.java#L75-L111","documentation":"JmxConnect uses picocli's executionStrategy to fetch the top-level command spec via its mixin key; that mixin holds the JmxConnect user object used to drive JMX connections. If the mixin is absent from the parse result's top-level hierarchy the wiring is broken and InitializationException is thrown during command initialization.","triggerScenarios":"Programmatic (embedded) invocation of JmxConnect without registering the mixin spec (setCommandSpec... MIXIN_KEY) on the top-level command; altered picocli command hierarchy in a custom runner.","commonSituations":"Embedding nodetool's JmxConnect in another tool; upgrading picocli and changing parse behavior; custom main() that builds the CommandLine without the standard spec setup.","solutions":["Ensure the top-level command spec includes the JmxConnect mixin (specMixin with MIXIN_KEY) before running","Use the standard nodetool entry point rather than invoking executionStrategy directly with a hand-built ParseResult","Pin the picocli version compatible with this Cassandra release"],"exampleFix":"// before\nnew CommandLine(new NodeTool()).execute(args)\n// after\nCommandLine cmd = new CommandLine(new NodeTool());\ncmd.getCommandSpec().addSubcommand(\"jmx\", new JmxConnect());\ncmd.execute(args);","handlingStrategy":"try-catch","validationCode":"// verify the top-level spec carries the mixin before executing\nCommandSpec jmx = parseResult.commandSpec().mixins().get(\"jmxConnect\");\nif (jmx == null) throw new IllegalStateException(\"JmxConnect mixin not registered\");","typeGuard":null,"tryCatchPattern":"try { JmxConnect.executionStrategy(parseResult); } catch (InitializationException e) { /* fix command hierarchy wiring */ }","preventionTips":["Always build the command via the standard nodetool main entry point","Register the JmxConnect mixin on the top-level spec in custom runners","Test embedded picocli hierarchies after picocli upgrades"],"tags":["cli","picocli","initialization"],"backgroundTag":"internal-invariant-violation","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"}