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

DuplicateOptionAnnotationsException when a nested group is defined inside a mixin #779

Closed
teoincontatto opened this issue Aug 6, 2019 · 4 comments
Milestone

Comments

@teoincontatto
Copy link

With version 4.0.2-SNAPSHOT I am facing a DuplicateOptionAnnotationsException in a particular use case. The mixin is using a nested group inside of a group. I managed to generate a simple test case that reproduce the issue:

  • Test code:
@picocli.CommandLine.Command(name = "test-with-mixin-and-nested-group",
    description = "Picocli section test with mixin and nested group.",
    abbreviateSynopsis = true,
    sortOptions = false)
public class Test {
  @Mixin
  TestConfig testConfig = new TestConfig();

  private static class TestConfig {
    @ArgGroup(validate = false, heading = "A1%n")
    private final A1 a1 = new A1();

    private static class A1 {
      @ArgGroup(exclusive = true)
      private final NestedA1 nestedA1 = new NestedA1();

      private static class NestedA1 {
        @Option(names = {"-ta1", "--test-a1"})
        private String testA1;
        @Option(names = {"-ta2", "--test-a2"})
        private String testA2;
      }
    }

    @ArgGroup(validate = false, heading = "A2%n")
    private final A2 a2 = new A2();

    private static class A2 {
      @Option(names = {"-tb1", "--test-b1"})
      private String testB1;
      @Option(names = {"-tb2", "--test-b2"})
      private String testB2;
    }
  }

  /**
   * Picocli test.
   */
  public static void main(String[] args) {
    new CommandLine(new Test()).usage(System.out);
  }
}
  • Output:
picocli.CommandLine$DuplicateOptionAnnotationsException: Option name '-ta2' is used by both field String com.ongres.egres.TestPicocliHeadingSection$TestWithNestedMixin$TestConfig$A1$NestedA1.testA2 and field String com.ongres.egres.TestPicocliHeadingSection$TestWithNestedMixin$TestConfig$A1$NestedA1.testA2
	at picocli.CommandLine$DuplicateOptionAnnotationsException.create(CommandLine.java:15027)
	at picocli.CommandLine$DuplicateOptionAnnotationsException.access$1700(CommandLine.java:15021)
	at picocli.CommandLine$Model$CommandSpec.addOption(CommandLine.java:5381)
	at picocli.CommandLine$Model$CommandSpec.addMixin(CommandLine.java:5567)
	at picocli.CommandLine$Model$CommandReflection.initFromAnnotatedTypedMembers(CommandLine.java:9641)
	at picocli.CommandLine$Model$CommandReflection.initFromAnnotatedFields(CommandLine.java:9621)
	at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:9532)
	at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:5116)
	at picocli.CommandLine.<init>(CommandLine.java:223)
	at picocli.CommandLine.<init>(CommandLine.java:196)
	at Test.main(Test.java:45)

Originally posted by @teoincontatto in #776 (comment)

@remkop remkop added this to the 4.0.2 milestone Aug 6, 2019
@remkop
Copy link
Owner

remkop commented Aug 6, 2019

Thank you again for raising this!
I think I know what the issue is and will commit a fix shortly.

@remkop remkop closed this as completed in 12e3b3f Aug 6, 2019
@remkop
Copy link
Owner

remkop commented Aug 6, 2019

Fixed in master.
Can you verify?

I plan to do a picocli-4.0.2 release that includes this fix later this week.

@teoincontatto
Copy link
Author

Confirmed!

@remkop
Copy link
Owner

remkop commented Aug 6, 2019

Thanks for the confirmation!

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