Browse Source

Refine null-safety in the spring-jms module

Closes gh-34157
pull/34171/head
Sébastien Deleuze 12 months ago
parent
commit
9516d9b822
  1. 2
      spring-core/src/main/java/org/springframework/util/CollectionUtils.java
  2. 2
      spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java
  3. 1
      spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java
  4. 2
      spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java
  5. 2
      spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java
  6. 4
      spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java

2
spring-core/src/main/java/org/springframework/util/CollectionUtils.java

@ -289,7 +289,7 @@ public abstract class CollectionUtils {
* or {@code null} if none or more than one such value found * or {@code null} if none or more than one such value found
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> @Nullable T findValueOfType(Collection<?> collection, @Nullable Class<T> type) { public static <T> @Nullable T findValueOfType(@Nullable Collection<?> collection, @Nullable Class<T> type) {
if (isEmpty(collection)) { if (isEmpty(collection)) {
return null; return null;
} }

2
spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java

@ -274,7 +274,7 @@ public abstract class ConnectionFactoryUtils {
* @return the transactional Session, or {@code null} if none found * @return the transactional Session, or {@code null} if none found
* @throws JMSException in case of JMS failure * @throws JMSException in case of JMS failure
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
public static @Nullable Session doGetTransactionalSession( public static @Nullable Session doGetTransactionalSession(
ConnectionFactory connectionFactory, ResourceFactory resourceFactory, boolean startConnection) ConnectionFactory connectionFactory, ResourceFactory resourceFactory, boolean startConnection)
throws JMSException { throws JMSException {

1
spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java

@ -215,7 +215,6 @@ public class JmsResourceHolder extends ResourceHolderSupport {
* Return this resource holder's Session of the given type * Return this resource holder's Session of the given type
* for the given connection, or {@code null} if none. * for the given connection, or {@code null} if none.
*/ */
@SuppressWarnings("NullAway")
public <S extends Session> @Nullable S getSession(Class<S> sessionType, @Nullable Connection connection) { public <S extends Session> @Nullable S getSession(Class<S> sessionType, @Nullable Connection connection) {
Deque<Session> sessions = Deque<Session> sessions =
(connection != null ? this.sessionsPerConnection.get(connection) : this.sessions); (connection != null ? this.sessionsPerConnection.get(connection) : this.sessions);

2
spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java

@ -323,7 +323,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
* @throws jakarta.jms.JMSException if thrown by JMS API methods * @throws jakarta.jms.JMSException if thrown by JMS API methods
* @see #initConnection() * @see #initConnection()
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Lazy initialization
protected Connection getConnection() throws JMSException { protected Connection getConnection() throws JMSException {
this.connectionLock.lock(); this.connectionLock.lock();
try { try {

2
spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

@ -1434,7 +1434,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
} }
} }
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Lazy initialization
private void initResourcesIfNecessary() throws JMSException { private void initResourcesIfNecessary() throws JMSException {
if (getCacheLevel() <= CACHE_CONNECTION) { if (getCacheLevel() <= CACHE_CONNECTION) {
updateRecoveryMarker(); updateRecoveryMarker();

4
spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java

@ -312,7 +312,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
* @throws JMSException if thrown by JMS methods * @throws JMSException if thrown by JMS methods
* @see #executeListener * @see #executeListener
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Lambda
protected MessageConsumer createListenerConsumer(final Session session) throws JMSException { protected MessageConsumer createListenerConsumer(final Session session) throws JMSException {
Destination destination = getDestination(); Destination destination = getDestination();
if (destination == null) { if (destination == null) {
@ -341,7 +341,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
* @see #executeListener * @see #executeListener
* @see #setExposeListenerSession * @see #setExposeListenerSession
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected void processMessage(Message message, Session session) { protected void processMessage(Message message, Session session) {
ConnectionFactory connectionFactory = getConnectionFactory(); ConnectionFactory connectionFactory = getConnectionFactory();
boolean exposeResource = (connectionFactory != null && isExposeListenerSession()); boolean exposeResource = (connectionFactory != null && isExposeListenerSession());

Loading…
Cancel
Save