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

"wrong number of arguments" exception when using inherited options with @Command-annotated methods #1042

Closed
remkop opened this issue May 13, 2020 · 5 comments
Milestone

Comments

@remkop
Copy link
Owner

remkop commented May 13, 2020

The inherited options (#649) feature introduced in picocli 4.3 causes an exception when used with @Command-annotated methods:

Code to reproduce the problem:

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import static picocli.CommandLine.ScopeType.INHERIT;

@Command(name = "top")
public class Top implements Runnable {

    @Option(names = {"--debug", "-d"}, scope = INHERIT)
    void setDebug(boolean debug) {
        System.out.println("Debug has been set to " + debug);
    }

    @Override
    public void run() {
        System.out.println("Running " + this);
    }

    @Command
    void sub() {
        System.out.println("Running sub");
    }

    public static void main(String[] args) {
        new CommandLine(new Top()).execute("sub", "--debug");
    }
}

Output:

Debug has been set to true
java.lang.IllegalArgumentException: wrong number of arguments
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1872)
	at picocli.CommandLine.access$1100(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2243)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2237)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2201)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2068)
	at picocli.CommandLine.execute(CommandLine.java:1978)
	at picocli.examples.inheritedoptions.Top.main(Top.java:35)
@remkop
Copy link
Owner Author

remkop commented May 13, 2020

Thank you @garretwilson for raising this!
I pushed a fix to master that addresses the issue.

Can I ask you a favor: can you take the new version for a spin with your use case(s)? It would be good to find if there are other issues not covered by the picocli tests before I publish a new release...

To verify, check out picocli master locally, and build it with publishToMavenLocal. That should publish picocli-4.3.1-SNAPSHOT to your local .m2 Maven cache.

git clone https://github.com/remkop/picocli.git
cd picocli
gradlew publishToMavenLocal

You can then try this in a project that uses the info.picocli:picocli:4.3.1-SNAPSHOT dependency. Feedback very welcome!

@garretwilson
Copy link

Man, @remkop , today was not my day. One roadblock after another. Eclipse bugs. Picocli bugs. Lots of other things that you weren't responsible for. 😆 Finally I gave up, watched movies, and drank beers. I guess that's what vacations days are for anyway.

I'm sorry but I won't be able to test this out as a -SNAPSHOT. I'm really sorry. I know it would be nice for you to get that pre-release feedback, but I'm so preoccupied (ocupado e preocupado, se falar português) with various things that I just won't be able to get to it. Do your best and I'll test the final release.

Boa sorte and thanks for filing this ticket for me.

Now I think I have one or two more beers in my quarantine lair here …

@remkop remkop closed this as completed May 14, 2020
@remkop
Copy link
Owner Author

remkop commented May 14, 2020

@garretwilson picocli 4.3.1 has been released. Enjoy! :-)

@garretwilson
Copy link

@remkop that seems to have fixed it. Thank you so much!

@remkop
Copy link
Owner Author

remkop commented May 16, 2020

Great! Make sure to use the latest version (4.3.2).

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