Refine null-safety in the spring-jms module

Closes gh-34157
This commit is contained in:
Sébastien Deleuze 2024-12-26 15:18:27 +01:00
parent be11e73d2c
commit 9516d9b822
6 changed files with 6 additions and 7 deletions

View File

@ -289,7 +289,7 @@ public abstract class CollectionUtils {
* or {@code null} if none or more than one such value found
*/
@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)) {
return null;
}

View File

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

View File

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

View File

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

View File

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

View File

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