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

Mutually Exclusive Options: stack overflow #661

Closed
deining opened this issue Apr 11, 2019 · 4 comments
Closed

Mutually Exclusive Options: stack overflow #661

deining opened this issue Apr 11, 2019 · 4 comments

Comments

@deining
Copy link
Contributor

deining commented Apr 11, 2019

How to reproduce:
Minimal working example:

package test;

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

public class ArgGroupsTest {

    public static void main(String[] args) {
        CommandLine cmd = new CommandLine(new TestCommand());
        cmd.parseArgs("-a=Foo");
        cmd.parseWithHandler(new CommandLine.RunAll(), args);
    }

    @Command(name = "ArgGroupsTest")
    static class TestCommand implements Runnable {

        @ArgGroup( exclusive = true)
        DataSource datasource;

        static class DataSource {
            @Option(names = "-a", required = true, defaultValue = "Strings.gxl")
            static String aString;
        }

        @Override
        public void run() {
            // nothing to do here
        }
    }
}

If I remove defaultValue = "Strings.gxl"from the annotation of option -a, the error goes away.

Stack trace:

Exception in thread "main" java.lang.StackOverflowError
	at picocli.CommandLine$Help$Ansi.apply(CommandLine.java:12026)
	at picocli.CommandLine$Help$ColorScheme.optionText(CommandLine.java:11737)
	at picocli.CommandLine$Model$ArgGroupSpec.concatOptionText(CommandLine.java:6630)
	at picocli.CommandLine$Model$ArgGroupSpec.synopsisText(CommandLine.java:6602)
	at picocli.CommandLine$Model$ArgGroupSpec.synopsis(CommandLine.java:6593)
	at picocli.CommandLine$ParseResult$MatchedGroup.addMultiple(CommandLine.java:8438)
	at picocli.CommandLine$ParseResult$MatchedGroup.<init>(CommandLine.java:8422)
        ...
       quite a few lines here
@remkop
Copy link
Owner

remkop commented Apr 11, 2019

Thanks for raising this! This bug exposed a deeper bug that I'm still wresting with...

@remkop remkop added this to the 4.0-alpha-2 milestone Apr 11, 2019
@remkop remkop closed this as completed in 41616af Apr 12, 2019
@remkop
Copy link
Owner

remkop commented Apr 12, 2019

Fixed in master. Thanks again for raising this.
Hoping to release alpha-2 in a few days.

@mitamr
Copy link

mitamr commented Oct 24, 2019

Was this released? I am still facing this bug

@remkop
Copy link
Owner

remkop commented Oct 24, 2019

@mitamr Yes the fix for the above issue was included in picocli-4.0.0-alpha-2 and all following releases. I just tried the above example with picocli 4.0.4 and it works fine: no StackOverflowError.

If you are still seeing this with picocli 4.0.4 you found a new similar issue. Can you please raise a new ticket with an example of how to reproduce the issue?

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

3 participants