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

@@ -63,7 +63,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
/**
* Set the {@link JmsListenerEndpointRegistry} instance to use.
*/
public void setEndpointRegistry(JmsListenerEndpointRegistry endpointRegistry) {
public void setEndpointRegistry(@Nullable JmsListenerEndpointRegistry endpointRegistry) {
this.endpointRegistry = endpointRegistry;
}
@@ -84,7 +84,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
* or to customize conversion and validation support. See
* {@link DefaultMessageHandlerMethodFactory} javadoc for more details.
*/
public void setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory) {
public void setMessageHandlerMethodFactory(@Nullable MessageHandlerMethodFactory messageHandlerMethodFactory) {
this.messageHandlerMethodFactory = messageHandlerMethodFactory;
}

View File

@@ -68,7 +68,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
/**
* Set the actual bean instance to invoke this endpoint method on.
*/
public void setBean(Object bean) {
public void setBean(@Nullable Object bean) {
this.bean = bean;
}
@@ -80,7 +80,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
/**
* Set the method to invoke for processing a message managed by this endpoint.
*/
public void setMethod(Method method) {
public void setMethod(@Nullable Method method) {
this.method = method;
}
@@ -95,7 +95,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
* (if annotated itself, that is, if not just annotated in an interface).
* @since 4.2.3
*/
public void setMostSpecificMethod(Method mostSpecificMethod) {
public void setMostSpecificMethod(@Nullable Method mostSpecificMethod) {
this.mostSpecificMethod = mostSpecificMethod;
}

View File

@@ -39,7 +39,7 @@ public class SimpleJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
* Set the {@link MessageListener} to invoke when a message matching
* the endpoint is received.
*/
public void setMessageListener(MessageListener messageListener) {
public void setMessageListener(@Nullable MessageListener messageListener) {
this.messageListener = messageListener;
}

View File

@@ -55,6 +55,7 @@ import org.springframework.util.Assert;
public class DelegatingConnectionFactory
implements SmartConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean {
@Nullable
private ConnectionFactory targetConnectionFactory;
private boolean shouldStopConnections = false;
@@ -63,8 +64,7 @@ public class DelegatingConnectionFactory
/**
* Set the target ConnectionFactory that this ConnectionFactory should delegate to.
*/
public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) {
Assert.notNull(targetConnectionFactory, "'targetConnectionFactory' must not be null");
public void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory) {
this.targetConnectionFactory = targetConnectionFactory;
}

View File

@@ -127,8 +127,8 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
/**
* Set the JMS ConnectionFactory that this instance should manage transactions for.
*/
public void setConnectionFactory(ConnectionFactory cf) {
if (cf instanceof TransactionAwareConnectionFactoryProxy) {
public void setConnectionFactory(@Nullable ConnectionFactory cf) {
if (cf != null && cf instanceof TransactionAwareConnectionFactoryProxy) {
// If we got a TransactionAwareConnectionFactoryProxy, we need to perform transactions
// for its underlying target ConnectionFactory, else JMS access code won't see
// properly exposed transactions (i.e. transactions for the target ConnectionFactory).

View File

@@ -143,7 +143,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
* Set the target ConnectionFactory which will be used to lazily
* create a single Connection.
*/
public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) {
public void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory) {
this.targetConnectionFactory = targetConnectionFactory;
}
@@ -151,7 +151,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
* Return the target ConnectionFactory which will be used to lazily
* create a single Connection, if any.
*/
@org.springframework.lang.Nullable
@Nullable
public ConnectionFactory getTargetConnectionFactory() {
return this.targetConnectionFactory;
}
@@ -165,7 +165,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
* @see javax.jms.Connection#setClientID
* @see #setTargetConnectionFactory
*/
public void setClientId(String clientId) {
public void setClientId(@Nullable String clientId) {
this.clientId = clientId;
}
@@ -173,7 +173,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
* Return a JMS client ID for the single Connection created and exposed
* by this ConnectionFactory, if any.
*/
@org.springframework.lang.Nullable
@Nullable
protected String getClientId() {
return this.clientId;
}
@@ -183,7 +183,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
* registered with the single Connection created by this factory.
* @see #setReconnectOnException
*/
public void setExceptionListener(ExceptionListener exceptionListener) {
public void setExceptionListener(@Nullable ExceptionListener exceptionListener) {
this.exceptionListener = exceptionListener;
}

View File

@@ -81,6 +81,7 @@ public class TransactionAwareConnectionFactoryProxy
private boolean synchedLocalTransactionAllowed = false;
@Nullable
private ConnectionFactory targetConnectionFactory;
@@ -102,8 +103,7 @@ public class TransactionAwareConnectionFactoryProxy
/**
* Set the target ConnectionFactory that this ConnectionFactory should delegate to.
*/
public final void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) {
Assert.notNull(targetConnectionFactory, "'targetConnectionFactory' must not be null");
public final void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory) {
this.targetConnectionFactory = targetConnectionFactory;
}

View File

@@ -106,7 +106,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination>
/**
* Set the {@link JmsTemplate} to use.
*/
public void setJmsTemplate(JmsTemplate jmsTemplate) {
public void setJmsTemplate(@Nullable JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
@@ -147,7 +147,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination>
* without a destination argument will raise an exception if invoked.
* @see #setDefaultDestination(Object)
*/
public void setDefaultDestinationName(String defaultDestinationName) {
public void setDefaultDestinationName(@Nullable String defaultDestinationName) {
this.defaultDestinationName = defaultDestinationName;
}

View File

@@ -92,6 +92,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
private final JmsTemplateResourceFactory transactionalResourceFactory = new JmsTemplateResourceFactory();
@Nullable
private Object defaultDestination;
private MessageConverter messageConverter;
@@ -161,7 +162,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
* @see #convertAndSend(Object, MessagePostProcessor)
* @see #setDefaultDestinationName(String)
*/
public void setDefaultDestination(Destination destination) {
public void setDefaultDestination(@Nullable Destination destination) {
this.defaultDestination = destination;
}
@@ -195,7 +196,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
* @see #setDestinationResolver
* @see #setDefaultDestination(javax.jms.Destination)
*/
public void setDefaultDestinationName(String destinationName) {
public void setDefaultDestinationName(@Nullable String destinationName) {
this.defaultDestination = destinationName;
}
@@ -234,7 +235,6 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
/**
* Return the message converter for this template.
*/
@Nullable
public MessageConverter getMessageConverter() {
return this.messageConverter;
}

View File

@@ -84,7 +84,7 @@ public abstract class JmsGatewaySupport implements InitializingBean {
* Set the JmsTemplate for the gateway.
* @see #setConnectionFactory(javax.jms.ConnectionFactory)
*/
public final void setJmsTemplate(JmsTemplate jmsTemplate) {
public final void setJmsTemplate(@Nullable JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}

View File

@@ -96,7 +96,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
* @see javax.jms.Connection#setClientID
* @see #setConnectionFactory
*/
public void setClientId(String clientId) {
public void setClientId(@Nullable String clientId) {
this.clientId = clientId;
}
@@ -143,7 +143,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
}
@Override
public void setBeanName(String beanName) {
public void setBeanName(@Nullable String beanName) {
this.beanName = beanName;
}

View File

@@ -196,8 +196,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
* @see #setDestinationName(String)
*/
public void setDestination(Destination destination) {
Assert.notNull(destination, "'destination' must not be null");
public void setDestination(@Nullable Destination destination) {
this.destination = destination;
if (destination instanceof Topic && !(destination instanceof Queue)) {
// Clearly a Topic: let's set the "pubSubDomain" flag accordingly.
@@ -226,8 +225,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
* @see #setDestination(javax.jms.Destination)
*/
public void setDestinationName(String destinationName) {
Assert.notNull(destinationName, "'destinationName' must not be null");
public void setDestinationName(@Nullable String destinationName) {
this.destination = destinationName;
}
@@ -286,10 +284,10 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* @see javax.jms.MessageListener
* @see SessionAwareMessageListener
*/
public void setMessageListener(Object messageListener) {
public void setMessageListener(@Nullable Object messageListener) {
checkMessageListener(messageListener);
this.messageListener = messageListener;
if (this.subscriptionName == null) {
if (messageListener != null && this.subscriptionName == null) {
this.subscriptionName = getDefaultSubscriptionName(messageListener);
}
}
@@ -313,8 +311,8 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* @see javax.jms.MessageListener
* @see SessionAwareMessageListener
*/
protected void checkMessageListener(Object messageListener) {
if (!(messageListener instanceof MessageListener ||
protected void checkMessageListener(@Nullable Object messageListener) {
if (messageListener != null && !(messageListener instanceof MessageListener ||
messageListener instanceof SessionAwareMessageListener)) {
throw new IllegalArgumentException(
"Message listener needs to be of type [" + MessageListener.class.getName() +
@@ -408,7 +406,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* @see #setClientId
* @see #setMessageListener
*/
public void setSubscriptionName(String subscriptionName) {
public void setSubscriptionName(@Nullable String subscriptionName) {
this.subscriptionName = subscriptionName;
}
@@ -435,9 +433,9 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* @see #setClientId
* @see #setMessageListener
*/
public void setDurableSubscriptionName(String durableSubscriptionName) {
public void setDurableSubscriptionName(@Nullable String durableSubscriptionName) {
this.subscriptionName = durableSubscriptionName;
this.subscriptionDurable = true;
this.subscriptionDurable = (durableSubscriptionName != null);
}
/**
@@ -529,7 +527,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* Set the JMS ExceptionListener to notify in case of a JMSException thrown
* by the registered message listener or the invocation infrastructure.
*/
public void setExceptionListener(ExceptionListener exceptionListener) {
public void setExceptionListener(@Nullable ExceptionListener exceptionListener) {
this.exceptionListener = exceptionListener;
}
@@ -548,7 +546,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
* <p>By default, there will be <b>no</b> ErrorHandler so that error-level
* logging is the only result.
*/
public void setErrorHandler(ErrorHandler errorHandler) {
public void setErrorHandler(@Nullable ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}

View File

@@ -123,7 +123,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe
* @see org.springframework.transaction.jta.JtaTransactionManager
* @see org.springframework.jms.connection.JmsTransactionManager
*/
public void setTransactionManager(PlatformTransactionManager transactionManager) {
public void setTransactionManager(@Nullable PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}

View File

@@ -142,7 +142,7 @@ public abstract class AbstractAdaptableMessageListener
* {@link javax.jms.TextMessage TextMessages} and
* {@link javax.jms.ObjectMessage ObjectMessages}.
*/
public void setMessageConverter(MessageConverter messageConverter) {
public void setMessageConverter(@Nullable MessageConverter messageConverter) {
this.messageConverter = messageConverter;
}

View File

@@ -78,7 +78,7 @@ public class JmsActivationSpecConfig {
private MessageConverter messageConverter;
public void setDestinationName(String destinationName) {
public void setDestinationName(@Nullable String destinationName) {
this.destinationName = destinationName;
}
@@ -108,7 +108,7 @@ public class JmsActivationSpecConfig {
}
}
public void setReplyQosSettings(QosSettings replyQosSettings) {
public void setReplyQosSettings(@Nullable QosSettings replyQosSettings) {
this.replyQosSettings = replyQosSettings;
}
@@ -139,7 +139,7 @@ public class JmsActivationSpecConfig {
return this.subscriptionShared;
}
public void setSubscriptionName(String subscriptionName) {
public void setSubscriptionName(@Nullable String subscriptionName) {
this.subscriptionName = subscriptionName;
}
@@ -148,9 +148,9 @@ public class JmsActivationSpecConfig {
return this.subscriptionName;
}
public void setDurableSubscriptionName(String durableSubscriptionName) {
public void setDurableSubscriptionName(@Nullable String durableSubscriptionName) {
this.subscriptionName = durableSubscriptionName;
this.subscriptionDurable = true;
this.subscriptionDurable = (durableSubscriptionName != null);
}
@Nullable
@@ -158,7 +158,7 @@ public class JmsActivationSpecConfig {
return (this.subscriptionDurable ? this.subscriptionName : null);
}
public void setClientId(String clientId) {
public void setClientId(@Nullable String clientId) {
this.clientId = clientId;
}
@@ -167,7 +167,7 @@ public class JmsActivationSpecConfig {
return this.clientId;
}
public void setMessageSelector(String messageSelector) {
public void setMessageSelector(@Nullable String messageSelector) {
this.messageSelector = messageSelector;
}
@@ -274,7 +274,7 @@ public class JmsActivationSpecConfig {
* Set the {@link MessageConverter} strategy for converting JMS Messages.
* @param messageConverter the message converter to use
*/
public void setMessageConverter(MessageConverter messageConverter) {
public void setMessageConverter(@Nullable MessageConverter messageConverter) {
this.messageConverter = messageConverter;
}

View File

@@ -138,7 +138,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager
* <p>This config object will be turned into a concrete JCA 1.5 ActivationSpec
* object through a {@link #setActivationSpecFactory JmsActivationSpecFactory}.
*/
public void setActivationSpecConfig(JmsActivationSpecConfig activationSpecConfig) {
public void setActivationSpecConfig(@Nullable JmsActivationSpecConfig activationSpecConfig) {
this.activationSpecConfig = activationSpecConfig;
}

View File

@@ -90,7 +90,7 @@ public class StandardJmsActivationSpecFactory implements JmsActivationSpecFactor
* or {@link org.springframework.jms.support.destination.BeanFactoryDestinationResolver}
* but not {@link org.springframework.jms.support.destination.DynamicDestinationResolver}.
*/
public void setDestinationResolver(DestinationResolver destinationResolver) {
public void setDestinationResolver(@Nullable DestinationResolver destinationResolver) {
this.destinationResolver = destinationResolver;
}

View File

@@ -92,7 +92,7 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
/**
* Set the QueueConnectionFactory to use for obtaining JMS QueueConnections.
*/
public void setConnectionFactory(ConnectionFactory connectionFactory) {
public void setConnectionFactory(@Nullable ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}

View File

@@ -54,6 +54,7 @@ public abstract class JmsAccessor implements InitializingBean {
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private ConnectionFactory connectionFactory;
private boolean sessionTransacted = false;
@@ -64,7 +65,7 @@ public abstract class JmsAccessor implements InitializingBean {
/**
* Set the ConnectionFactory to use for obtaining JMS {@link Connection Connections}.
*/
public void setConnectionFactory(ConnectionFactory connectionFactory) {
public void setConnectionFactory(@Nullable ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}