Skip to content

Commit

Permalink
Update to get testIssue1300BooleanInitialization to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTheSnowman committed Aug 8, 2022
1 parent 01530df commit afb435e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9074,6 +9074,8 @@ public Object initialValue() {
if (initialValueState == InitialValueState.POSTPONED && annotatedElement != null) {
try {
initialValue = annotatedElement.getter().get();
if(annotatedElement.getTypeInfo().getType() == boolean.class && initialValue == null)
initialValue = false;
initialValueState = InitialValueState.CACHED; // only if successfully initialized
} catch (Exception ex) { } // #1300 if error: keep initialValueState == POSTPONED
}
Expand Down Expand Up @@ -12024,7 +12026,9 @@ public <T> T get() throws PicocliException {
try { obj = scope.get(); }
catch (Exception ex) { throw new PicocliException("Could not get scope for field " + field, ex); }
try {
@SuppressWarnings("unchecked") T result = (T) field.get(obj);
// wtfacoconut
@SuppressWarnings("unchecked") T result = obj == null ? null : (T) field.get(obj);
//@SuppressWarnings("unchecked") T result = (T) field.get(obj);
return result;
} catch (Exception ex) {
throw new PicocliException("Could not get value for field " + field, ex);
Expand All @@ -12033,7 +12037,9 @@ public <T> T get() throws PicocliException {
public <T> T set(T value) throws PicocliException {
Object obj;
try { obj = scope.get(); }
catch (Exception ex) { throw new PicocliException("Could not get scope for field " + field, ex); }
catch (Exception ex) {
throw new PicocliException("Could not get scope for field " + field, ex);
}
try {
@SuppressWarnings("unchecked") T result = (T) field.get(obj);
field.set(obj, value);
Expand Down

0 comments on commit afb435e

Please sign in to comment.