Skip to content

Mutually Exclusive Options: stack overflow #661

@deining

Description

@deining

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions