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

Method subcommand with inherited mixed-in standard help options: failure #1303

Closed
deining opened this issue Jan 10, 2021 · 2 comments
Closed
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Milestone

Comments

@deining
Copy link
Contributor

deining commented Jan 10, 2021

Minimum working example:

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

@Command(scope = ScopeType.INHERIT, mixinStandardHelpOptions = true)
public class InheritApp  {

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

    public static void main (String... args) {
        new CommandLine(new InheritApp()).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:64)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	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 InheritApp.main(InheritApp.java:14)

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

@remkop remkop added this to the 4.7 milestone Jan 10, 2021
@remkop
Copy link
Owner

remkop commented Jan 10, 2021

@deining Thank you for raising this and thank you for the example to reproduce the issue!
Looking into this...

@remkop remkop closed this as completed in 77cb05d Jan 11, 2021
@remkop
Copy link
Owner

remkop commented Jan 11, 2021

Thanks again for raising this!

In a nutshell: the cause had to do with calculating argument indexes for subcommand methods; the mixinStandardHelpOptions = true does not add method parameters, so is given special treatment. However, when scope = ScopeType.INHERIT, this special treatment should not be applied.

This is now fixed in master.

@remkop remkop added the theme: parser An issue or change related to the parser label Jan 25, 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
…e mismatch` error in method subcommands with inherited mixed-in standard help options

Closes remkop#1303
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ment type mismatch` error in method subcommands with inherited mixed-in standard help options"

This reverts commit e5b6320.
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ment type mismatch` error in method subcommands with inherited mixed-in standard help options"

This reverts commit e5b6320.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants