Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ArgGroup with @Option methods fail with NullPointerException #829

Closed
a2geek opened this issue Oct 3, 2019 · 4 comments
Closed

@ArgGroup with @Option methods fail with NullPointerException #829

a2geek opened this issue Oct 3, 2019 · 4 comments
Labels
theme: arg-group An issue or change related to argument groups type: bug 🐛
Milestone

Comments

@a2geek
Copy link

a2geek commented Oct 3, 2019

What I'm trying to do: I have an existing API that has multiple values for list formats and I would like to switch them on with a flag type mechanism. They are mutually exclusive -- you can't have a short and a long list format, for instance.

This seems to be a great chance to use @ArgGroup(exclusive = true) and @Option(...) on a method in the exclusive options. The method simply sets the correct value to the actual parameter. (There are multiple methods settings values. One for each list format.)

What happens: A NullPointerException is generated like this:

$ bin/picocli-experiments list file1 file2
NullPointerException: null while processing argument at or before arg[0] 'list' in [list, file1, file2]: java.lang.NullPointerException

If I switch from a method to a boolean flag annotated with @Option, and then write the if-logic to calculate the value, it works fine. But that's pretty ugly.

From what little I've been able to determine from debugging, the scope is never set in Interpreter.applyGroupDefaults() in line 11075 -- the if (arg.scope().get() != null) is what fails.

Using picocli version 4.0.4.

(P.S. Excellent tool, really like it a lot.)

(P.P.S. sample.zip is attached for a more cohesive use case.)

@remkop
Copy link
Owner

remkop commented Oct 3, 2019

Thanks for raising this.
Looking at it...

@remkop remkop added this to the 4.0.5 milestone Oct 3, 2019
@remkop
Copy link
Owner

remkop commented Oct 3, 2019

I’ve only been able to spend a little bit of time investigating, but I suspect that this only happens in subcommands. All my tests for argument groups are with top-level commands. Definitely some problem in the initialization.
Still need to look further...

@a2geek
Copy link
Author

a2geek commented Oct 3, 2019

Thanks for the quick confirmation! I was uncertain if I was missing something or not. I'll go with the alternative mechanism for now then. :-)

@remkop remkop added the theme: arg-group An issue or change related to argument groups label Oct 8, 2019
@remkop remkop closed this as completed in 70091a2 Oct 8, 2019
@remkop
Copy link
Owner

remkop commented Oct 8, 2019

Fixed in master. Thanks again for raising this!

remkop added a commit that referenced this issue Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: arg-group An issue or change related to argument groups type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants