Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/982#discussion_r214700788
--- Diff:
core/src/main/java/org/apache/brooklyn/util/core/flags/MethodCoercions.java ---
@@ -87,13 +89,23 @@ public boolean apply(@Nullable Method input) {
Method accessibleMethod =
Reflections.findAccessibleMethod(method).get();
try {
Type paramType = method.getGenericParameterTypes()[0];
- Object coercedArgument = TypeCoercions.coerce(argument,
TypeToken.of(paramType));
- return Maybe.of(accessibleMethod.invoke(instance,
coercedArgument));
+ Maybe<?> coercedArgumentM =
TypeCoercions.tryCoerce(argument, TypeToken.of(paramType));
+ RuntimeException exception =
Maybe.getException(coercedArgumentM);
--- End diff --
The javadoc on `Maybe.getException` claimed it would return null for
present items; I relied on this and then discovered the error so updated the
code to bring it in line with the javadoc.
Can change back if you like but personally I think it's useful to be able
to get `null` back as an exception, saves a little bit of work sometimes, as in
this case: because we set `exception` manually in the boxing case we'd need
one more line than you suggest.
---