Make getters and setters null-safety consistent

This commit ensure that null-safety is consistent between
getters and setters in order to be able to provide beans
with properties with a common type when type safety is
taken in account like with Kotlin.

It also add a few missing property level @Nullable
annotations.

Issue: SPR-15792
This commit is contained in:
Sebastien Deleuze
2017-07-19 08:55:05 +02:00
parent ff85726fa9
commit fb4ddb0746
201 changed files with 579 additions and 489 deletions

View File

@@ -92,7 +92,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
/**
* Set the {@link Marshaller} to be used by this message converter.
*/
public void setMarshaller(Marshaller marshaller) {
public void setMarshaller(@Nullable Marshaller marshaller) {
this.marshaller = marshaller;
}
@@ -107,7 +107,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
/**
* Set the {@link Unmarshaller} to be used by this message converter.
*/
public void setUnmarshaller(Unmarshaller unmarshaller) {
public void setUnmarshaller(@Nullable Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}

View File

@@ -51,8 +51,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
* require resolving a destination name will raise an {@link IllegalArgumentException}.
* @param destinationResolver the destination resolver to use
*/
public void setDestinationResolver(DestinationResolver<D> destinationResolver) {
Assert.notNull(destinationResolver, "'destinationResolver' is required");
public void setDestinationResolver(@Nullable DestinationResolver<D> destinationResolver) {
this.destinationResolver = destinationResolver;
}

View File

@@ -63,7 +63,7 @@ public abstract class AbstractMessageSendingTemplate<D> implements MessageSendin
* a destination argument. If a default destination is not configured, send methods
* without a destination argument will raise an exception if invoked.
*/
public void setDefaultDestination(D defaultDestination) {
public void setDefaultDestination(@Nullable D defaultDestination) {
this.defaultDestination = defaultDestination;
}

View File

@@ -96,6 +96,7 @@ public abstract class AbstractMethodMessageHandler<T>
private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =
new HandlerMethodReturnValueHandlerComposite();
@Nullable
private ApplicationContext applicationContext;
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<>(64);
@@ -211,7 +212,7 @@ public abstract class AbstractMethodMessageHandler<T>
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
public void setApplicationContext(@Nullable ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

View File

@@ -121,8 +121,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor {
return (SimpMessageType) getHeader(MESSAGE_TYPE_HEADER);
}
public void setDestination(String destination) {
Assert.notNull(destination, "Destination must not be null");
public void setDestination(@Nullable String destination) {
setHeader(DESTINATION_HEADER, destination);
}
@@ -155,7 +154,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor {
/**
* A static alternative for access to the session attributes header.
*/
public void setSessionAttributes(Map<String, Object> attributes) {
public void setSessionAttributes(@Nullable Map<String, Object> attributes) {
setHeader(SESSION_ATTRIBUTES, attributes);
}
@@ -168,7 +167,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor {
return (Map<String, Object>) getHeader(SESSION_ATTRIBUTES);
}
public void setUser(Principal principal) {
public void setUser(@Nullable Principal principal) {
setHeader(USER_HEADER, principal);
}

View File

@@ -111,7 +111,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
* messages created through the {@code SimpMessagingTemplate}.
* <p>By default, this property is not set.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -121,7 +121,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
* messages sent to the client outbound channel.
* <p>By default this property is not set.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -234,7 +234,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
* @see org.springframework.validation.annotation.Validated
* @see PayloadArgumentResolver
*/
public void setValidator(Validator validator) {
public void setValidator(@Nullable Validator validator) {
this.validator = validator;
}
@@ -249,7 +249,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
* that send messages from controller return values.
* <p>By default, this property is not set.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -63,6 +63,7 @@ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturn
private final MessageSendingOperations<String> messagingTemplate;
@Nullable
private MessageHeaderInitializer headerInitializer;
@@ -82,7 +83,7 @@ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturn
* messages sent to the client outbound channel.
* <p>By default this property is not set.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -129,7 +129,7 @@ public abstract class AbstractBrokerMessageHandler
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
public void setApplicationEventPublisher(@Nullable ApplicationEventPublisher publisher) {
this.eventPublisher = publisher;
}

View File

@@ -157,10 +157,9 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
* <p>By default this is not set.
* @since 4.2
*/
public void setTaskScheduler(TaskScheduler taskScheduler) {
Assert.notNull(taskScheduler, "TaskScheduler must not be null");
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler) {
this.taskScheduler = taskScheduler;
if (this.heartbeatValue == null) {
if (taskScheduler != null && this.heartbeatValue == null) {
this.heartbeatValue = new long[] {10000, 10000};
}
}
@@ -183,8 +182,8 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
* (in milliseconds).
* @since 4.2
*/
public void setHeartbeatValue(long[] heartbeat) {
if (heartbeat.length != 2 || heartbeat[0] < 0 || heartbeat[1] < 0) {
public void setHeartbeatValue(@Nullable long[] 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;
@@ -205,7 +204,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
* <p>By default this property is not set.
* @since 4.1
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -112,7 +112,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
public void setApplicationContext(@Nullable ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

View File

@@ -325,7 +325,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
* providing the cloud-based STOMP service.
* <p>By default this property is not set.
*/
public void setVirtualHost(String virtualHost) {
public void setVirtualHost(@Nullable String virtualHost) {
this.virtualHost = virtualHost;
}
@@ -341,7 +341,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
* Configure a TCP client for managing TCP connections to the STOMP broker.
* <p>By default {@link ReactorNettyTcpClient} is used.
*/
public void setTcpClient(TcpOperations<byte[]> tcpClient) {
public void setTcpClient(@Nullable TcpOperations<byte[]> tcpClient) {
this.tcpClient = tcpClient;
}
@@ -361,7 +361,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
* are sent to the client outbound message channel.
* <p>By default this property is not set.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -43,6 +43,7 @@ public abstract class StompClientSupport {
private MessageConverter messageConverter = new SimpleMessageConverter();
@Nullable
private TaskScheduler taskScheduler;
private long[] defaultHeartbeat = new long[] {10000, 10000};
@@ -76,7 +77,7 @@ public abstract class StompClientSupport {
* Receipts however, if needed, do require a TaskScheduler to be configured.
* <p>By default, this is not set.
*/
public void setTaskScheduler(TaskScheduler taskScheduler) {
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler) {
this.taskScheduler = taskScheduler;
}

View File

@@ -61,7 +61,7 @@ public class StompDecoder {
* Configure a {@link MessageHeaderInitializer} to apply to the headers of
* {@link Message}s from decoded STOMP frames.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -246,7 +246,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet());
}
public void setHost(String host) {
public void setHost(@Nullable String host) {
setNativeHeader(STOMP_HOST_HEADER, host);
}
@@ -302,7 +302,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
setNativeHeader(STOMP_HEARTBEAT_HEADER, cx + "," + cy);
}
public void setAck(String ack) {
public void setAck(@Nullable String ack) {
setNativeHeader(STOMP_ACK_HEADER, ack);
}
@@ -311,7 +311,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_ACK_HEADER);
}
public void setNack(String nack) {
public void setNack(@Nullable String nack) {
setNativeHeader(STOMP_NACK_HEADER, nack);
}
@@ -320,7 +320,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_NACK_HEADER);
}
public void setLogin(String login) {
public void setLogin(@Nullable String login) {
setNativeHeader(STOMP_LOGIN_HEADER, login);
}
@@ -329,7 +329,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_LOGIN_HEADER);
}
public void setPasscode(String passcode) {
public void setPasscode(@Nullable String passcode) {
setNativeHeader(STOMP_PASSCODE_HEADER, passcode);
protectPasscode();
}
@@ -351,7 +351,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return (credentials != null ? credentials.passcode : null);
}
public void setReceiptId(String receiptId) {
public void setReceiptId(@Nullable String receiptId) {
setNativeHeader(STOMP_RECEIPT_ID_HEADER, receiptId);
}
@@ -360,7 +360,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_RECEIPT_ID_HEADER);
}
public void setReceipt(String receiptId) {
public void setReceipt(@Nullable String receiptId) {
setNativeHeader(STOMP_RECEIPT_HEADER, receiptId);
}
@@ -374,7 +374,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_MESSAGE_HEADER);
}
public void setMessage(String content) {
public void setMessage(@Nullable String content) {
setNativeHeader(STOMP_MESSAGE_HEADER, content);
}
@@ -383,7 +383,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_MESSAGE_ID_HEADER);
}
public void setMessageId(String id) {
public void setMessageId(@Nullable String id) {
setNativeHeader(STOMP_MESSAGE_ID_HEADER, id);
}
@@ -392,7 +392,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
return getFirstNativeHeader(STOMP_VERSION_HEADER);
}
public void setVersion(String version) {
public void setVersion(@Nullable String version) {
setNativeHeader(STOMP_VERSION_HEADER, version);
}

View File

@@ -126,10 +126,15 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the content-type header.
* Applies to the SEND, MESSAGE, and ERROR frames.
*/
public void setContentType(MimeType mimeType) {
Assert.isTrue(!mimeType.isWildcardType(), "'Content-Type' cannot contain wildcard type '*'");
Assert.isTrue(!mimeType.isWildcardSubtype(), "'Content-Type' cannot contain wildcard subtype '*'");
set(CONTENT_TYPE, mimeType.toString());
public void setContentType(@Nullable MimeType mimeType) {
if (mimeType != null) {
Assert.isTrue(!mimeType.isWildcardType(), "'Content-Type' cannot contain wildcard type '*'");
Assert.isTrue(!mimeType.isWildcardSubtype(), "'Content-Type' cannot contain wildcard subtype '*'");
set(CONTENT_TYPE, mimeType.toString());
}
else {
set(CONTENT_TYPE, null);
}
}
/**
@@ -161,7 +166,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the receipt header.
* Applies to any client frame other than CONNECT.
*/
public void setReceipt(String receipt) {
public void setReceipt(@Nullable String receipt) {
set(RECEIPT, receipt);
}
@@ -177,7 +182,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the host header.
* Applies to the CONNECT frame.
*/
public void setHost(String host) {
public void setHost(@Nullable String host) {
set(HOST, host);
}
@@ -193,7 +198,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the login header.
* Applies to the CONNECT frame.
*/
public void setLogin(String login) {
public void setLogin(@Nullable String login) {
set(LOGIN, login);
}
@@ -209,7 +214,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the passcode header.
* Applies to the CONNECT frame.
*/
public void setPasscode(String passcode) {
public void setPasscode(@Nullable String passcode) {
set(PASSCODE, passcode);
}
@@ -263,7 +268,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the session header.
* Applies to the CONNECTED frame.
*/
public void setSession(String session) {
public void setSession(@Nullable String session) {
set(SESSION, session);
}
@@ -279,7 +284,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the server header.
* Applies to the CONNECTED frame.
*/
public void setServer(String server) {
public void setServer(@Nullable String server) {
set(SERVER, server);
}
@@ -295,7 +300,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
/**
* Set the destination header.
*/
public void setDestination(String destination) {
public void setDestination(@Nullable String destination) {
set(DESTINATION, destination);
}
@@ -312,7 +317,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the id header.
* Applies to the SUBSCR0BE, UNSUBSCRIBE, and ACK or NACK frames.
*/
public void setId(String id) {
public void setId(@Nullable String id) {
set(ID, id);
}
@@ -328,7 +333,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the ack header to one of "auto", "client", or "client-individual".
* Applies to the SUBSCRIBE and MESSAGE frames.
*/
public void setAck(String ack) {
public void setAck(@Nullable String ack) {
set(ACK, ack);
}
@@ -344,7 +349,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the login header.
* Applies to the MESSAGE frame.
*/
public void setSubscription(String subscription) {
public void setSubscription(@Nullable String subscription) {
set(SUBSCRIPTION, subscription);
}
@@ -360,7 +365,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the message-id header.
* Applies to the MESSAGE frame.
*/
public void setMessageId(String messageId) {
public void setMessageId(@Nullable String messageId) {
set(MESSAGE_ID, messageId);
}
@@ -376,7 +381,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Set the receipt-id header.
* Applies to the RECEIPT frame.
*/
public void setReceiptId(String receiptId) {
public void setReceiptId(@Nullable String receiptId) {
set(RECEIPT_ID, receiptId);
}
@@ -433,7 +438,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* @see #add(String, String)
*/
@Override
public void set(String headerName, String headerValue) {
public void set(String headerName, @Nullable String headerValue) {
List<String> headerValues = new LinkedList<>();
headerValues.add(headerValue);
headers.put(headerName, headerValues);

View File

@@ -108,7 +108,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
* <p>By default this is not set.
* @param destination the target destination.
*/
public void setBroadcastDestination(String destination) {
public void setBroadcastDestination(@Nullable String destination) {
this.broadcastHandler = (StringUtils.hasText(destination) ?
new BroadcastHandler(this.messagingTemplate, destination) : null);
}
@@ -134,7 +134,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
* headers of resolved target messages.
* <p>By default this is not set.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
}

View File

@@ -43,7 +43,7 @@ public class IdTimestampMessageHeaderInitializer implements MessageHeaderInitial
* IdGenerator of {@link org.springframework.messaging.MessageHeaders} is used.
* <p>To have no id's generated at all, see {@link #setDisableIdGeneration()}.
*/
public void setIdGenerator(IdGenerator idGenerator) {
public void setIdGenerator(@Nullable IdGenerator idGenerator) {
this.idGenerator = idGenerator;
}