Skip to content

Incorrect results when using ArgGroup + defaultValue + split + List/Set #2349

@mithungonsalvez

Description

@mithungonsalvez

Hello,

When using the features ArgsGroup along with defaultValue and split, the value reported from the second group is not correct as per the arguments provided.

Sample code with error:

public class TestParser {

    public static void main(String[] ignore) {
        String[] rawArgs = new String[]{
                "--type=ONE", "--actions=CREATE,DELETE",
                "--type=TWO", "--actions=CREATE",
                "--type=THREE",
                "--type=FOUR", "--actions=CREATE,UPDATE"
        };
        Args args = new Args();
        new CommandLine(args).parseArgs(rawArgs);

        args.groups.forEach(g -> System.out.printf("%5s = %s\n", g.type, g.actions));
    }

    public static class Args {
        @ArgGroup(exclusive = false, multiplicity = "1..4")
        private List<Group> groups;
    }

    public static class Group {
        @Option(names = "--type", required = true)
        private String type;

        @Option(names = "--actions", defaultValue = "CREATE,UPDATE,DELETE", split = ",")
        private Set<String> actions;
    }

}

Actual Result:

  ONE = [CREATE, DELETE]
  TWO = [CREATE, UPDATE, DELETE]
THREE = [CREATE, UPDATE, DELETE]
 FOUR = [CREATE, UPDATE, DELETE]

Expected Result:

  ONE = [CREATE, DELETE]
  TWO = [CREATE]
THREE = [CREATE, UPDATE, DELETE]
 FOUR = [CREATE, UPDATE]

Here, we can see that the results are using the default value starting from the second item in the ArgGroup.

Details:

JDK: temurin-21.jdk
Picocli version: 4.7.6

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions