From 28fe7a02fad747fecac0641a65b9c523c2473881 Mon Sep 17 00:00:00 2001 From: Marko Mackic Date: Sun, 17 Oct 2021 21:33:45 +0200 Subject: [PATCH] Revert "[#1300] Bugfix: Avoid spurious warning "Could not set initial value for field boolean"" This reverts commit ff6d808b02fc0c6c4bb7dbd8ecbbd3b7437ef1d6. --- RELEASE-NOTES.md | 1 - src/main/java/picocli/CommandLine.java | 6 ++-- src/test/java/picocli/ArgGroupTest.java | 39 ------------------------- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2d052363e..507f2f433 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -19,7 +19,6 @@ Picocli follows [semantic versioning](http://semver.org/). ## 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. diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 319d8b565..498890dbc 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -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; } diff --git a/src/test/java/picocli/ArgGroupTest.java b/src/test/java/picocli/ArgGroupTest.java index 23cdd0604..5534d7289 100644 --- a/src/test/java/picocli/ArgGroupTest.java +++ b/src/test/java/picocli/ArgGroupTest.java @@ -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; @@ -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()); - } }