Skip to content

Commit

Permalink
[#1440] Fix annotation processor bug: ensure that commands have uniqu…
Browse files Browse the repository at this point in the history
…e subcommand instances

Closes #1440
  • Loading branch information
remkop committed Jan 18, 2022
1 parent 50a724d commit ed222fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Picocli follows [semantic versioning](http://semver.org/).


## <a name="4.6.3-fixes"></a> Fixed issues
* [#1440] Bugfix: annotation processor incorrectly failed with `DuplicateOptionAnnotationsException` when multiple commands had a subcommand in common and an inherited (`scope = ScopeType.INHERIT`) option. Thanks to [nemetsSY](https://github.com/nemetsSY) for raising this.
* [#1384][#1493] Bugfix: parser now correctly handles ArgGroups with optional positional parameters. Thanks to [Matthew Lewis](https://github.com/mattjlewis) for raising this and to [Kurt Kaiser](https://github.com/kurtkaiser) for the pull request.
* [#1474] Bugfix: Avoid `UnsupportedCharsetException: cp65001` on Microsoft Windows console when code page is set to UTF-8. Thanks to [epuni](https://github.com/epuni) for raising this.
* [#1466][#1467] Bugfix/Enhancement: Autocomplete now shows subcommand aliases in the completion candidates. Thanks to [Ruud Senden](https://github.com/rsenden) for the pull request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static com.google.testing.compile.Compiler.javac;

public class Issue1440Test {
@Ignore("https://github.com/remkop/picocli/issues/1440")
//@Ignore("https://github.com/remkop/picocli/issues/1440")
@Test
public void testIssue1440() {
Processor processor = new AnnotatedCommandSourceGeneratorProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Spec;

@Command(name = "Command1", subcommands = CommandLine.HelpCommand.class,
@Command(name = "Command2", subcommands = CommandLine.HelpCommand.class,
description = "Command 1 description")
class Command2 {
@Spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,17 @@ private void buildCommands(RoundEnvironment roundEnv, Context context) {
}

private CommandSpec buildCommand(Element element, final Context context, final RoundEnvironment roundEnv) {
return buildCommand(true, element, context, roundEnv);
}
private CommandSpec buildCommand(boolean reuseExisting, Element element, final Context context, final RoundEnvironment roundEnv) {
debugElement(element, "@Command");

CommandSpec result = context.commands.get(element);
if (result != null) {
return result;
CommandSpec result = null;
if (reuseExisting) { // #1440 subcommands should create separate instances
result = context.commands.get(element);
if (result != null) {
return result;
}
}
result = CommandSpec.wrapWithoutInspection(element);
result.interpolateVariables(false);
Expand Down Expand Up @@ -387,7 +393,7 @@ private void registerSubcommands(List<AnnotationValue> typeMirrors,
logger.fine("Processing subcommand: " + subcommandElement);

if (isValidSubcommandHasNameAttribute(subcommandElement)) {
CommandSpec commandSpec = buildCommand(subcommandElement, context, roundEnv);
CommandSpec commandSpec = buildCommand(false, subcommandElement, context, roundEnv);
result.add(commandSpec);
}
}
Expand Down

0 comments on commit ed222fe

Please sign in to comment.