You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a confusing NPE when trying to add a programmatically created subcommand using CommandLine#addSubCommand(String, Object).
picocli.CommandLine$InitializationException: Unable to initialize @ParentCommand field: java.lang.NullPointerException
at picocli.CommandLine$Model$CommandReflection.initParentCommand(CommandLine.java:4186)
at picocli.CommandLine.addSubcommand(CommandLine.java:234)
Caused by: java.lang.NullPointerException
at picocli.CommandLine$Model$CommandReflection.initParentCommand(CommandLine.java:4175)
I took a look and it's because CommandLine#addSubCommand(String, Object) calls the userObject() method on the parent and subcommand, which returms null for both. Then the CommandReflection#initParentCommand(Object, Object) method tries calling getClass() on one of the null values, creating the NPE.
I can get around this issue using CommandLine.getSubcommands() and modifying the map it returns or simply adding the commands on the CommandSpec object instead.
Can you confirm this as a bug or is this intended behavior I just don't understand?
Kind regards
The text was updated successfully, but these errors were encountered:
Hello,
I had a confusing NPE when trying to add a programmatically created subcommand using
CommandLine#addSubCommand(String, Object)
.I took a look and it's because
CommandLine#addSubCommand(String, Object)
calls theuserObject()
method on the parent and subcommand, which returms null for both. Then theCommandReflection#initParentCommand(Object, Object)
method tries callinggetClass()
on one of the null values, creating the NPE.I can get around this issue using
CommandLine.getSubcommands()
and modifying the map it returns or simply adding the commands on theCommandSpec
object instead.Can you confirm this as a bug or is this intended behavior I just don't understand?
Kind regards
The text was updated successfully, but these errors were encountered: