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

Annotation processor fails on subcommands with mixins (4.0.0) #769

Closed
MortronMeymo opened this issue Jul 18, 2019 · 7 comments
Closed

Annotation processor fails on subcommands with mixins (4.0.0) #769

MortronMeymo opened this issue Jul 18, 2019 · 7 comments
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Milestone

Comments

@MortronMeymo
Copy link

The annotation processor fails with a duplicate option exception when a subcommand uses a mixin.
Minimal example:

import picocli.CommandLine;

class Mixin {
    @CommandLine.Option(names = {"--some-option"})
    public String someOption;
}

@CommandLine.Command(name = "SubCommand")
class SubCommand {
    @CommandLine.Mixin
    public Mixin someMixin;
}

@CommandLine.Command(name = "Command", subcommands = {SubCommand.class})
class Command {
}

Annotation processor output:

error: FATAL ERROR: picocli.CommandLine$DuplicateOptionAnnotationsException: Option name '--some-option' is used by both field String Mixin.someOption and field String Mixin.someOption
        at picocli.CommandLine$DuplicateOptionAnnotationsException.create(CommandLine.java:15020)
        at picocli.CommandLine$DuplicateOptionAnnotationsException.access$1700(CommandLine.java:15014)
        at picocli.CommandLine$Model$CommandSpec.addOption(CommandLine.java:5381)
        at picocli.CommandLine$Model$CommandSpec.addMixin(CommandLine.java:5560)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$MixinInfo.addMixin(AbstractCommandSpecProcessor.java:896)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.connectModel(AbstractCommandSpecProcessor.java:851)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.access$000(AbstractCommandSpecProcessor.java:754)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.tryProcess(AbstractCommandSpecProcessor.java:162)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.process(AbstractCommandSpecProcessor.java:133)
        at org.gradle.api.internal.tasks.compile.processing.DelegatingProcessor.process(DelegatingProcessor.java:62)
        at org.gradle.api.internal.tasks.compile.processing.NonIncrementalProcessor.process(NonIncrementalProcessor.java:45)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:972)
 ...
@remkop remkop added type: bug 🐛 theme: codegen An issue or change related to the picocli-codegen module labels Jul 19, 2019
@remkop remkop added this to the 4.0.1 milestone Jul 19, 2019
@remkop
Copy link
Owner

remkop commented Jul 19, 2019

Thank you for the bug report! Investigating...

@remkop
Copy link
Owner

remkop commented Jul 19, 2019

I found the cause. Basically, mixins are discovered twice and stored in an internal datastructure twice. There is a de-duplication step missing which results in the mixins being added twice, giving the error you are seeing. I'll fix this as soon as possible.

@remkop remkop closed this as completed in a0d6539 Jul 19, 2019
@remkop
Copy link
Owner

remkop commented Jul 19, 2019

I pushed a fix for this issue to master.
Please verify.

@MortronMeymo
Copy link
Author

Verified. The processor now runs fine on this example as well as my real project.

All I need now is for it to generate Java code and then I'm 100% happy :)

@remkop
Copy link
Owner

remkop commented Jul 19, 2019

Thanks for the verification!

About code generation: I did some initial work on this, which is currently just used for testing (see the test I added in the commit to fix this bug). One of the goals is to be able to run without reflection (#539). That will take a while longer. :-)

@remkop
Copy link
Owner

remkop commented Jul 19, 2019

I released picocli 4.0.1 with the fix for this bug: https://github.com/remkop/picocli/releases/tag/v4.0.1
Thanks again for the bug report!

@remkop
Copy link
Owner

remkop commented Jul 19, 2019

...and don’t be shy to star picocli on GitHub and tell your friends if you like the project! :-P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants