Refine null-safety in spring-messaging
See gh-32475
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.messaging;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception that indicates an error occurred during message delivery.
|
||||
*
|
||||
@@ -37,11 +39,11 @@ public class MessageDeliveryException extends MessagingException {
|
||||
super(undeliveredMessage, description);
|
||||
}
|
||||
|
||||
public MessageDeliveryException(Message<?> message, Throwable cause) {
|
||||
public MessageDeliveryException(Message<?> message, @Nullable Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public MessageDeliveryException(Message<?> undeliveredMessage, String description, Throwable cause) {
|
||||
public MessageDeliveryException(Message<?> undeliveredMessage, String description, @Nullable Throwable cause) {
|
||||
super(undeliveredMessage, description, cause);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MessagingException extends NestedRuntimeException {
|
||||
this.failedMessage = message;
|
||||
}
|
||||
|
||||
public MessagingException(Message<?> message, Throwable cause) {
|
||||
public MessagingException(Message<?> message, @Nullable Throwable cause) {
|
||||
super(null, cause);
|
||||
this.failedMessage = message;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,8 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
||||
}
|
||||
|
||||
// Do not log warning for serializer not found (note: different message wording on Jackson 2.9)
|
||||
boolean debugLevel = (cause instanceof JsonMappingException && cause.getMessage().startsWith("Cannot find"));
|
||||
boolean debugLevel = (cause instanceof JsonMappingException && cause.getMessage() != null
|
||||
&& cause.getMessage().startsWith("Cannot find"));
|
||||
|
||||
if (debugLevel ? logger.isDebugEnabled() : logger.isWarnEnabled()) {
|
||||
String msg = "Failed to evaluate Jackson " + (type instanceof JavaType ? "de" : "") +
|
||||
|
||||
@@ -80,6 +80,7 @@ public class CompositeMessageCondition implements MessageCondition<CompositeMess
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CompositeMessageCondition getMatchingCondition(Message<?> message) {
|
||||
List<MessageCondition<?>> result = new ArrayList<>(this.messageConditions.size());
|
||||
for (MessageCondition<?> condition : this.messageConditions) {
|
||||
|
||||
@@ -81,6 +81,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object resolveArgumentValue(MethodParameter parameter, Message<?> message) {
|
||||
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
|
||||
MethodParameter nestedParameter = parameter.nestedIfOptional();
|
||||
|
||||
@@ -272,6 +272,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected CompositeMessageCondition getMappingForMethod(Method method, Class<?> handlerType) {
|
||||
CompositeMessageCondition methodCondition = getCondition(method);
|
||||
if (methodCondition != null) {
|
||||
@@ -325,12 +326,14 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<C
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected RouteMatcher.Route getDestination(Message<?> message) {
|
||||
return (RouteMatcher.Route) message.getHeaders()
|
||||
.get(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message<?> message) {
|
||||
return mapping.getMatchingCondition(message);
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
|
||||
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
|
||||
MethodParameter nestedParameter = parameter.nestedIfOptional();
|
||||
|
||||
@@ -111,7 +111,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
* @see #doInvoke
|
||||
*/
|
||||
@Nullable
|
||||
public Object invoke(Message<?> message, Object... providedArgs) throws Exception {
|
||||
public Object invoke(Message<?> message, @Nullable Object... providedArgs) throws Exception {
|
||||
Object[] args = getMethodArgumentValues(message, providedArgs);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Arguments: " + Arrays.toString(args));
|
||||
@@ -125,7 +125,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
* <p>The resulting array will be passed into {@link #doInvoke}.
|
||||
* @since 5.1.2
|
||||
*/
|
||||
protected Object[] getMethodArgumentValues(Message<?> message, Object... providedArgs) throws Exception {
|
||||
protected Object[] getMethodArgumentValues(Message<?> message, @Nullable Object... providedArgs) throws Exception {
|
||||
MethodParameter[] parameters = getMethodParameters();
|
||||
if (ObjectUtils.isEmpty(parameters)) {
|
||||
return EMPTY_ARGS;
|
||||
|
||||
@@ -23,6 +23,7 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ReactiveAdapter;
|
||||
import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Support for single-value reactive types (like {@code Mono} or {@code Single})
|
||||
@@ -57,6 +58,7 @@ public class ReactiveReturnValueHandler extends AbstractAsyncReturnValueHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
|
||||
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue);
|
||||
if (adapter != null) {
|
||||
|
||||
@@ -134,6 +134,7 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition<R
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public RSocketFrameTypeMessageCondition getMatchingCondition(Message<?> message) {
|
||||
FrameType actual = message.getHeaders().get(FRAME_TYPE_HEADER, FrameType.class);
|
||||
if (actual != null) {
|
||||
|
||||
@@ -247,6 +247,7 @@ public final class RSocketServiceProxyFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Method method = invocation.getMethod();
|
||||
RSocketServiceMethod serviceMethod = this.serviceMethods.get(method);
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.security.Principal;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
@@ -40,6 +41,7 @@ public class PrincipalMethodArgumentResolver implements HandlerMethodArgumentRes
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object resolveArgument(MethodParameter parameter, Message<?> message){
|
||||
Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders());
|
||||
return parameter.isOptional() ? Optional.ofNullable(user) : user;
|
||||
|
||||
@@ -476,6 +476,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected String getLookupDestination(@Nullable String destination) {
|
||||
if (destination == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user