Revisit Assert to avoid single-arg assert methods (with refined messages)
Issue: SPR-15196
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -94,7 +94,9 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
|
||||
throws Exception {
|
||||
|
||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||
Assert.notNull(handler, "No handler for return value type [" + returnType.getParameterType().getName() + "]");
|
||||
if (handler == null) {
|
||||
throw new IllegalStateException("No handler for return value type: " + returnType.getParameterType());
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Processing return value with " + handler);
|
||||
}
|
||||
@@ -104,14 +106,15 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
|
||||
@Override
|
||||
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
|
||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||
return (handler != null && handler instanceof AsyncHandlerMethodReturnValueHandler &&
|
||||
return (handler instanceof AsyncHandlerMethodReturnValueHandler &&
|
||||
((AsyncHandlerMethodReturnValueHandler) handler).isAsyncReturnValue(returnValue, returnType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) {
|
||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||
Assert.isTrue(handler != null && handler instanceof AsyncHandlerMethodReturnValueHandler);
|
||||
Assert.state(handler instanceof AsyncHandlerMethodReturnValueHandler,
|
||||
"AsyncHandlerMethodReturnValueHandler required");
|
||||
return ((AsyncHandlerMethodReturnValueHandler) handler).toListenableFuture(returnValue, returnType);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -58,10 +58,10 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||
|
||||
/**
|
||||
* Create a new {@link SimpMessagingTemplate} instance.
|
||||
* @param messageChannel the message channel (must not be {@code null})
|
||||
* @param messageChannel the message channel (never {@code null})
|
||||
*/
|
||||
public SimpMessagingTemplate(MessageChannel messageChannel) {
|
||||
Assert.notNull(messageChannel, "'messageChannel' must not be null");
|
||||
Assert.notNull(messageChannel, "MessageChannel must not be null");
|
||||
this.messageChannel = messageChannel;
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||
* @see org.springframework.messaging.simp.user.UserDestinationMessageHandler
|
||||
*/
|
||||
public void setUserDestinationPrefix(String prefix) {
|
||||
Assert.hasText(prefix, "'destinationPrefix' must not be empty");
|
||||
this.destinationPrefix = prefix.endsWith("/") ? prefix : prefix + "/";
|
||||
Assert.hasText(prefix, "User destination prefix must not be empty");
|
||||
this.destinationPrefix = (prefix.endsWith("/") ? prefix : prefix + "/");
|
||||
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||
*/
|
||||
@Override
|
||||
public void send(Message<?> message) {
|
||||
Assert.notNull(message, "'message' is required");
|
||||
Assert.notNull(message, "Message is required");
|
||||
String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders());
|
||||
if (destination != null) {
|
||||
sendInternal(message);
|
||||
@@ -178,7 +178,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||
|
||||
private void sendInternal(Message<?> message) {
|
||||
String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders());
|
||||
Assert.notNull(destination);
|
||||
Assert.notNull(destination, "Destination header required");
|
||||
|
||||
long timeout = this.sendTimeout;
|
||||
boolean sent = (timeout >= 0 ? this.messageChannel.send(message, timeout) : this.messageChannel.send(message));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -480,7 +480,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(pattern, lookupDestination);
|
||||
if (!CollectionUtils.isEmpty(vars)) {
|
||||
MessageHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
|
||||
Assert.state(mha != null && mha.isMutable());
|
||||
Assert.state(mha != null && mha.isMutable(), "Mutable MessageHeaderAccessor required");
|
||||
mha.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.messaging.simp.broker;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -174,7 +175,9 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setHeartbeatValue(long[] heartbeat) {
|
||||
Assert.notNull(heartbeat);
|
||||
if (heartbeat == null || heartbeat.length != 2 || heartbeat[0] < 0 || heartbeat[1] < 0) {
|
||||
throw new IllegalArgumentException("Invalid heart-beat: " + Arrays.toString(heartbeat));
|
||||
}
|
||||
this.heartbeatValue = heartbeat;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -317,14 +317,14 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
return new NoOpMessageHandler();
|
||||
}
|
||||
SimpUserRegistry userRegistry = userRegistry();
|
||||
Assert.isInstanceOf(MultiServerUserRegistry.class, userRegistry);
|
||||
Assert.isInstanceOf(MultiServerUserRegistry.class, userRegistry, "MultiServerUserRegistry required");
|
||||
return new UserRegistryMessageHandler((MultiServerUserRegistry) userRegistry,
|
||||
brokerMessagingTemplate(), getBrokerRegistry().getUserRegistryBroadcast(),
|
||||
messageBrokerTaskScheduler());
|
||||
}
|
||||
|
||||
// Expose alias for 4.1 compatibility
|
||||
@Bean(name={"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
|
||||
@Bean(name = {"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
|
||||
public ThreadPoolTaskScheduler messageBrokerTaskScheduler() {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setThreadNamePrefix("MessageBroker-");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,8 +55,8 @@ public class MessageBrokerRegistry {
|
||||
|
||||
|
||||
public MessageBrokerRegistry(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {
|
||||
Assert.notNull(clientInboundChannel);
|
||||
Assert.notNull(clientOutboundChannel);
|
||||
Assert.notNull(clientInboundChannel, "Inbound channel must not be null");
|
||||
Assert.notNull(clientOutboundChannel, "Outbound channel must not be null");
|
||||
this.clientInboundChannel = clientInboundChannel;
|
||||
this.clientOutboundChannel = clientOutboundChannel;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -175,7 +175,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
|
||||
* <p>By default set to 15,000 (15 seconds).
|
||||
*/
|
||||
public void setReceiptTimeLimit(long receiptTimeLimit) {
|
||||
Assert.isTrue(receiptTimeLimit > 0);
|
||||
Assert.isTrue(receiptTimeLimit > 0, "Receipt time limit must be larger than zero");
|
||||
this.receiptTimeLimit = receiptTimeLimit;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -126,7 +126,7 @@ public abstract class StompClientSupport {
|
||||
* <p>By default set to 15,000 (15 seconds).
|
||||
*/
|
||||
public void setReceiptTimeLimit(long receiptTimeLimit) {
|
||||
Assert.isTrue(receiptTimeLimit > 0);
|
||||
Assert.isTrue(receiptTimeLimit > 0, "Receipt time limit must be larger than zero");
|
||||
this.receiptTimeLimit = receiptTimeLimit;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,7 +48,7 @@ abstract class AbstractMonoToListenableFutureAdapter<S, T> implements Listenable
|
||||
|
||||
|
||||
protected AbstractMonoToListenableFutureAdapter(Mono<S> mono) {
|
||||
Assert.notNull(mono, "'mono' must not be null");
|
||||
Assert.notNull(mono, "Mono must not be null");
|
||||
this.monoProcessor = mono
|
||||
.doOnSuccess(result -> {
|
||||
T adapted;
|
||||
@@ -73,10 +73,8 @@ abstract class AbstractMonoToListenableFutureAdapter<S, T> implements Listenable
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
|
||||
Assert.notNull(unit);
|
||||
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
Assert.notNull(unit, "TimeUnit must not be null");
|
||||
Duration duration = Duration.ofMillis(TimeUnit.MILLISECONDS.convert(timeout, unit));
|
||||
S result = this.monoProcessor.block(duration);
|
||||
return adapt(result);
|
||||
@@ -112,6 +110,7 @@ abstract class AbstractMonoToListenableFutureAdapter<S, T> implements Listenable
|
||||
this.registry.addFailureCallback(failureCallback);
|
||||
}
|
||||
|
||||
|
||||
protected abstract T adapt(S result);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user