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

Subcommand overriding inherited mixed-in standard help options: IllegalArgumentException #1331

Closed
deining opened this issue Feb 22, 2021 · 2 comments
Milestone

Comments

@deining
Copy link
Contributor

deining commented Feb 22, 2021

Minimum working example:

import picocli.CommandLine;
import picocli.CommandLine.ScopeType;
import picocli.CommandLine.*;

@Command(scope = ScopeType.INHERIT)
public class InheritHelpApp  {

    @Command(mixinStandardHelpOptions = true)
    void sub(@Option(names = "-foo") int foo) {
        System.out.printf("Foo: %d", foo);
    }

    public static void main (String... args) {
        new CommandLine(new InheritHelpApp()).execute("sub", "-foo", "42" );
    }
}

When running this code, I'm getting

java.lang.IllegalArgumentException: argument type mismatch
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1972)
	at picocli.CommandLine.access$1300(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
	at picocli.CommandLine.execute(CommandLine.java:2078)
	at InheritHelpApp.main(InheritHelpApp.java:14)

It's the combination of inherited scope + mixinStandardHelpOptions = true on the method subcommand that's causing trouble here. If I set scope to ScopeType.LOCAL, the sample runs fine.

@remkop
Copy link
Owner

remkop commented Feb 23, 2021

Thank you for raising this and the example. I can reproduce this.
Investigating...

@remkop remkop added this to the 4.7 milestone Feb 23, 2021
remkop added a commit that referenced this issue Feb 23, 2021
Avoid `IllegalArgumentException` when parent has no standard help options and `scope = INHERIT`, while subcommand does have mixed-in standard help options.
@remkop
Copy link
Owner

remkop commented Feb 23, 2021

Great catch!

There was a logic bug that ended up removing the mixed-in standard help options from the subcommand, because it inherited from the parent and the parent did not have the mixed-in standard help options...

Thank you very much for raising this!

@remkop remkop closed this as completed Feb 23, 2021
@remkop remkop modified the milestones: 4.7, 4.6.2 Feb 23, 2021
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
Avoid `IllegalArgumentException` when parent has no standard help options and `scope = INHERIT`, while subcommand does have mixed-in standard help options.
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants