Skip to content

Commit

Permalink
Revert "[remkop#1300] Bugfix: Avoid spurious warning "Could not set i…
Browse files Browse the repository at this point in the history
…nitial value for field boolean""

This reverts commit ff6d808.
  • Loading branch information
MarkoMackic committed Oct 17, 2021
1 parent 60dc166 commit 28fe7a0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 44 deletions.
1 change: 0 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Picocli follows [semantic versioning](http://semver.org/).


## <a name="4.6.2-fixes"></a> Fixed issues
* [#1300] Bugfix: Avoid spurious warning "Could not set initial value for field boolean" when reusing `CommandLine` with ArgGroup. Thanks to [Yashodhan Ghadge](https://github.com/codexetreme) for raising this.
* [#1296] DOC: add Kotlin code samples to user manual; other user manual improvements. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request.
* [#1299] DOC: Link to `IParameterPreprocessor` from `IParameterConsumer` javadoc. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request.

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -8788,10 +8788,8 @@ public String mapFallbackValue() {
public Object initialValue() {
// not not initialize if already CACHED, or UNAVAILABLE, or if annotatedElement==null
if (initialValueState == InitialValueState.POSTPONED && annotatedElement != null) {
try {
initialValue = annotatedElement.getter().get();
initialValueState = InitialValueState.CACHED; // only if successfully initialized
} catch (Exception ex) { } // #1300 if error: keep initialValueState == POSTPONED
try { initialValue = annotatedElement.getter().get(); } catch (Exception ex) { }
initialValueState = InitialValueState.CACHED;
}
return initialValue;
}
Expand Down
39 changes: 0 additions & 39 deletions src/test/java/picocli/ArgGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import picocli.test.Execution;
import picocli.test.Supplier;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -4008,41 +4006,4 @@ class App {
assertSame(cmd, pex.getCommandLine());
}
}

@Command(name = "list", version = "issue 1300 1.0",
mixinStandardHelpOptions = true,
description = "list all signals")
static class Issue1300 implements Runnable {

@ArgGroup(exclusive = true, multiplicity = "1")
SearchFilterArgs searchFilterArgs;

public void run() { }

static class SearchFilterArgs {
@Option(names = {"-A", "--all"}, required = true)
boolean getAllSignals;
@Option(names = {"-m", "--message-name"}, required = true)
String messageName;
}
}
@Test
public void testIssue1300BooleanInitialization() {
PrintStream err = System.err;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream capture = new PrintStream(baos, true);
System.setErr(capture);

//TestUtil.setTraceLevel("DEBUG");
CommandLine cmd = new CommandLine(new Issue1300());
cmd.getUsageMessage(); // this causes initial values of all options to be cached

//cmd.execute(); // this prints help, which also cause initial values to be cached
//System.err.println("===");

cmd.execute("-A");
capture.flush();
System.setErr(err);
assertEquals("", baos.toString());
}
}

0 comments on commit 28fe7a0

Please sign in to comment.