Skip to content

Commit

Permalink
[#381] Bugfix: Prevent NPE when adding programmatically created subco…
Browse files Browse the repository at this point in the history
…mmands to CommandLine.

Closes #381
  • Loading branch information
remkop committed May 23, 2018
1 parent 546844b commit 644cf2d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# picocli Release Notes

# <a name="3.0.2"></a> Picocli 3.0.2
The picocli community is pleased to announce picocli 3.0.2.

This release fixes a bug for programmatic configuration.

This is the thirty-first public release.
Picocli follows [semantic versioning](http://semver.org/).

## <a name="3.0.2"></a> Table of Contents
* [New and noteworthy](#3.0.2-new)
* [Promoted features](#3.0.2-promoted)
* [Fixed issues](#3.0.2-fixes)
* [Deprecations](#3.0.2-deprecated)
* [Potential breaking changes](#3.0.2-breaking-changes)

## <a name="3.0.2-new"></a> New and Noteworthy

## <a name="3.0.2-promoted"></a> Promoted Features
Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility.

No features have been promoted in this picocli release.

## <a name="3.0.2-fixes"></a> Fixed issues
- [#381] Bugfix: Prevent NPE when adding programmatically created subcommands to CommandLine. Thanks to [Mikusch](https://github.com/Mikusch) for the bug report.

## <a name="3.0.2-deprecated"></a> Deprecations
No features were deprecated in this release.

## <a name="3.0.2-breaking-changes"></a> Potential breaking changes
This release has no breaking changes.


# <a name="3.0.1"></a> Picocli 3.0.1
The picocli community is pleased to announce picocli 3.0.1.

Expand Down
1 change: 1 addition & 0 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -4171,6 +4171,7 @@ private static void initSubcommands(Command cmd, CommandSpec parent, IFactory fa
}
}
static void initParentCommand(Object subcommand, Object parent) {
if (subcommand == null) { return; }
try {
Class<?> cls = subcommand.getClass();
while (cls != null) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/picocli/CommandLineModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1572,4 +1572,24 @@ public <T> T set(T value) throws Exception {
assertEquals(null, values.get(0));
assertEquals("2", values.get(1));
}

@Test
public void test381_NPE_whenAddingSubcommand() {
CommandSpec toplevel = CommandSpec.create();
toplevel.addOption(OptionSpec.builder("-o").description("o option").build());

CommandSpec sub = CommandSpec.create();
sub.addOption(OptionSpec.builder("-x").description("x option").build());

CommandLine commandLine = new CommandLine(toplevel);
commandLine.addSubcommand("sub", sub); // NPE here
commandLine.usage(System.out);

String expected = String.format("" +
"Usage: <main class> [-o] [COMMAND]%n" +
" -o o option%n" +
"Commands:%n" +
" sub%n");
assertEquals(expected, systemOutRule.getLog());
}
}

0 comments on commit 644cf2d

Please sign in to comment.