Nullability fine-tuning around bean properties

Issue: SPR-15720
Issue: SPR-15792
This commit is contained in:
Juergen Hoeller
2017-07-19 11:43:58 +02:00
parent 06fc092be2
commit 9fc4fb10b0
31 changed files with 243 additions and 206 deletions

View File

@@ -79,11 +79,11 @@ import org.springframework.util.Assert;
public class TransactionAwareConnectionFactoryProxy
implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory {
private boolean synchedLocalTransactionAllowed = false;
@Nullable
private ConnectionFactory targetConnectionFactory;
private boolean synchedLocalTransactionAllowed = false;
/**
* Create a new TransactionAwareConnectionFactoryProxy.
@@ -103,16 +103,18 @@ public class TransactionAwareConnectionFactoryProxy
/**
* Set the target ConnectionFactory that this ConnectionFactory should delegate to.
*/
public final void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory) {
public final void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) {
Assert.notNull(targetConnectionFactory, "'targetConnectionFactory' must not be null");
this.targetConnectionFactory = targetConnectionFactory;
}
/**
* Return the target ConnectionFactory that this ConnectionFactory should delegate to.
*/
@Nullable
protected ConnectionFactory getTargetConnectionFactory() {
return this.targetConnectionFactory;
ConnectionFactory target = this.targetConnectionFactory;
Assert.state(target != null, "'targetConnectionFactory' is required");
return target;
}
/**
@@ -141,19 +143,19 @@ public class TransactionAwareConnectionFactoryProxy
@Override
public Connection createConnection() throws JMSException {
Connection targetConnection = this.targetConnectionFactory.createConnection();
Connection targetConnection = getTargetConnectionFactory().createConnection();
return getTransactionAwareConnectionProxy(targetConnection);
}
@Override
public Connection createConnection(String username, String password) throws JMSException {
Connection targetConnection = obtainTargetConnectionFactory().createConnection(username, password);
Connection targetConnection = getTargetConnectionFactory().createConnection(username, password);
return getTransactionAwareConnectionProxy(targetConnection);
}
@Override
public QueueConnection createQueueConnection() throws JMSException {
ConnectionFactory target = obtainTargetConnectionFactory();
ConnectionFactory target = getTargetConnectionFactory();
if (!(target instanceof QueueConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
}
@@ -163,7 +165,7 @@ public class TransactionAwareConnectionFactoryProxy
@Override
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
ConnectionFactory target = obtainTargetConnectionFactory();
ConnectionFactory target = getTargetConnectionFactory();
if (!(target instanceof QueueConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
}
@@ -173,7 +175,7 @@ public class TransactionAwareConnectionFactoryProxy
@Override
public TopicConnection createTopicConnection() throws JMSException {
ConnectionFactory target = obtainTargetConnectionFactory();
ConnectionFactory target = getTargetConnectionFactory();
if (!(target instanceof TopicConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
}
@@ -183,7 +185,7 @@ public class TransactionAwareConnectionFactoryProxy
@Override
public TopicConnection createTopicConnection(String username, String password) throws JMSException {
ConnectionFactory target = obtainTargetConnectionFactory();
ConnectionFactory target = getTargetConnectionFactory();
if (!(target instanceof TopicConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
}
@@ -193,28 +195,22 @@ public class TransactionAwareConnectionFactoryProxy
@Override
public JMSContext createContext() {
return obtainTargetConnectionFactory().createContext();
return getTargetConnectionFactory().createContext();
}
@Override
public JMSContext createContext(String userName, String password) {
return obtainTargetConnectionFactory().createContext(userName, password);
return getTargetConnectionFactory().createContext(userName, password);
}
@Override
public JMSContext createContext(String userName, String password, int sessionMode) {
return obtainTargetConnectionFactory().createContext(userName, password, sessionMode);
return getTargetConnectionFactory().createContext(userName, password, sessionMode);
}
@Override
public JMSContext createContext(int sessionMode) {
return obtainTargetConnectionFactory().createContext(sessionMode);
}
private ConnectionFactory obtainTargetConnectionFactory() {
ConnectionFactory target = getTargetConnectionFactory();
Assert.state(target != null, "'targetConnectionFactory' is required");
return target;
return getTargetConnectionFactory().createContext(sessionMode);
}
@@ -265,14 +261,14 @@ public class TransactionAwareConnectionFactoryProxy
}
else if (Session.class == method.getReturnType()) {
Session session = ConnectionFactoryUtils.getTransactionalSession(
obtainTargetConnectionFactory(), this.target, isSynchedLocalTransactionAllowed());
getTargetConnectionFactory(), this.target, isSynchedLocalTransactionAllowed());
if (session != null) {
return getCloseSuppressingSessionProxy(session);
}
}
else if (QueueSession.class == method.getReturnType()) {
QueueSession session = ConnectionFactoryUtils.getTransactionalQueueSession(
(QueueConnectionFactory) obtainTargetConnectionFactory(), (QueueConnection) this.target,
(QueueConnectionFactory) getTargetConnectionFactory(), (QueueConnection) this.target,
isSynchedLocalTransactionAllowed());
if (session != null) {
return getCloseSuppressingSessionProxy(session);
@@ -280,7 +276,7 @@ public class TransactionAwareConnectionFactoryProxy
}
else if (TopicSession.class == method.getReturnType()) {
TopicSession session = ConnectionFactoryUtils.getTransactionalTopicSession(
(TopicConnectionFactory) obtainTargetConnectionFactory(), (TopicConnection) this.target,
(TopicConnectionFactory) getTargetConnectionFactory(), (TopicConnection) this.target,
isSynchedLocalTransactionAllowed());
if (session != null) {
return getCloseSuppressingSessionProxy(session);

View File

@@ -95,6 +95,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
@Nullable
private Object defaultDestination;
@Nullable
private MessageConverter messageConverter;
@@ -228,13 +229,14 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
* @see #receiveAndConvert
* @see org.springframework.jms.support.converter.SimpleMessageConverter
*/
public void setMessageConverter(MessageConverter messageConverter) {
public void setMessageConverter(@Nullable MessageConverter messageConverter) {
this.messageConverter = messageConverter;
}
/**
* Return the message converter for this template.
*/
@Nullable
public MessageConverter getMessageConverter() {
return this.messageConverter;
}

View File

@@ -65,6 +65,7 @@ public abstract class AbstractAdaptableMessageListener
private DestinationResolver destinationResolver = new DynamicDestinationResolver();
@Nullable
private MessageConverter messageConverter = new SimpleMessageConverter();
private final MessagingMessageConverterAdapter messagingMessageConverter = new MessagingMessageConverterAdapter();