Avoid null signals when resolving handler arguments

Prior to this commit, resolving an argument for a WebFlux controller
that's missing from the request and not required by the handler would
throw a NullPointerException in some cases.

This involves the conversion of the parameter (a `String` parameter type
might not trigger this behavior) and sending a `null` within a reactive
stream, which is illegal per the RS spec.

We now rely on a `Mono.justOrEmpty()` to handle those specific cases.

Issue: SPR-17050
(Cherry-picked from a7f97a1669)
This commit is contained in:
Brian Clozel
2018-07-18 14:41:43 +02:00
parent c0040a5508
commit 58f58e404e
2 changed files with 23 additions and 14 deletions

View File

@@ -100,13 +100,13 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr
Model model = bindingContext.getModel();
return resolveName(resolvedName.toString(), nestedParameter, exchange)
.map(arg -> {
.flatMap(arg -> {
if ("".equals(arg) && namedValueInfo.defaultValue != null) {
arg = resolveStringValue(namedValueInfo.defaultValue);
}
arg = applyConversion(arg, namedValueInfo, parameter, bindingContext, exchange);
handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange);
return arg;
return Mono.justOrEmpty(arg);
})
.switchIfEmpty(getDefaultValue(
namedValueInfo, parameter, bindingContext, model, exchange));