Skip to content

Commit d89b853

Browse files
committed
Add nullability annotations to module/spring-boot-jms
See gh-46587
1 parent 0638531 commit d89b853

File tree

9 files changed

+75
-56
lines changed

9 files changed

+75
-56
lines changed

documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.springframework.jms.config.DefaultJmsListenerContainerFactory
2828
class MyJmsConfiguration {
2929

3030
@Bean
31-
fun jmsListenerContainerFactory(connectionFactory: ConnectionFactory?,
31+
fun jmsListenerContainerFactory(connectionFactory: ConnectionFactory,
3232
configurer: DefaultJmsListenerContainerFactoryConfigurer): DefaultJmsListenerContainerFactory {
3333
val listenerFactory = DefaultJmsListenerContainerFactory()
3434
configurer.configure(listenerFactory, ConnectionFactoryUnwrapper.unwrapCaching(connectionFactory))

module/spring-boot-jms/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.jms;
1818

1919
import jakarta.jms.ConnectionFactory;
20+
import org.jspecify.annotations.Nullable;
2021
import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
2122

2223
import org.springframework.jms.connection.CachingConnectionFactory;
@@ -57,15 +58,16 @@ public static ConnectionFactory unwrapCaching(ConnectionFactory connectionFactor
5758
* @param connectionFactory a connection factory
5859
* @return the native connection factory that it wraps, if any
5960
*/
60-
public static ConnectionFactory unwrap(ConnectionFactory connectionFactory) {
61+
public static @Nullable ConnectionFactory unwrap(@Nullable ConnectionFactory connectionFactory) {
6162
if (connectionFactory instanceof CachingConnectionFactory cachingConnectionFactory) {
6263
return unwrap(cachingConnectionFactory.getTargetConnectionFactory());
6364
}
6465
ConnectionFactory unwrapedConnectionFactory = unwrapFromJmsPoolConnectionFactory(connectionFactory);
6566
return (unwrapedConnectionFactory != null) ? unwrap(unwrapedConnectionFactory) : connectionFactory;
6667
}
6768

68-
private static ConnectionFactory unwrapFromJmsPoolConnectionFactory(ConnectionFactory connectionFactory) {
69+
private static @Nullable ConnectionFactory unwrapFromJmsPoolConnectionFactory(
70+
@Nullable ConnectionFactory connectionFactory) {
6971
try {
7072
if (connectionFactory instanceof JmsPoolConnectionFactory jmsPoolConnectionFactory) {
7173
return (ConnectionFactory) jmsPoolConnectionFactory.getConnectionFactory();

module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/DefaultJmsListenerContainerFactoryConfigurer.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.micrometer.observation.ObservationRegistry;
2222
import jakarta.jms.ConnectionFactory;
2323
import jakarta.jms.ExceptionListener;
24+
import org.jspecify.annotations.Nullable;
2425

2526
import org.springframework.boot.context.properties.PropertyMapper;
2627
import org.springframework.boot.jms.autoconfigure.JmsProperties.Listener.Session;
@@ -46,24 +47,24 @@
4647
*/
4748
public final class DefaultJmsListenerContainerFactoryConfigurer {
4849

49-
private DestinationResolver destinationResolver;
50+
private @Nullable DestinationResolver destinationResolver;
5051

51-
private MessageConverter messageConverter;
52+
private @Nullable MessageConverter messageConverter;
5253

53-
private ExceptionListener exceptionListener;
54+
private @Nullable ExceptionListener exceptionListener;
5455

55-
private JtaTransactionManager transactionManager;
56+
private @Nullable JtaTransactionManager transactionManager;
5657

57-
private JmsProperties jmsProperties;
58+
private @Nullable JmsProperties jmsProperties;
5859

59-
private ObservationRegistry observationRegistry;
60+
private @Nullable ObservationRegistry observationRegistry;
6061

6162
/**
6263
* Set the {@link DestinationResolver} to use or {@code null} if no destination
6364
* resolver should be associated with the factory by default.
6465
* @param destinationResolver the {@link DestinationResolver}
6566
*/
66-
void setDestinationResolver(DestinationResolver destinationResolver) {
67+
void setDestinationResolver(@Nullable DestinationResolver destinationResolver) {
6768
this.destinationResolver = destinationResolver;
6869
}
6970

@@ -72,7 +73,7 @@ void setDestinationResolver(DestinationResolver destinationResolver) {
7273
* converter should be used.
7374
* @param messageConverter the {@link MessageConverter}
7475
*/
75-
void setMessageConverter(MessageConverter messageConverter) {
76+
void setMessageConverter(@Nullable MessageConverter messageConverter) {
7677
this.messageConverter = messageConverter;
7778
}
7879

@@ -81,7 +82,7 @@ void setMessageConverter(MessageConverter messageConverter) {
8182
* should be associated by default.
8283
* @param exceptionListener the {@link ExceptionListener}
8384
*/
84-
void setExceptionListener(ExceptionListener exceptionListener) {
85+
void setExceptionListener(@Nullable ExceptionListener exceptionListener) {
8586
this.exceptionListener = exceptionListener;
8687
}
8788

@@ -90,23 +91,23 @@ void setExceptionListener(ExceptionListener exceptionListener) {
9091
* should not be used.
9192
* @param transactionManager the {@link JtaTransactionManager}
9293
*/
93-
void setTransactionManager(JtaTransactionManager transactionManager) {
94+
void setTransactionManager(@Nullable JtaTransactionManager transactionManager) {
9495
this.transactionManager = transactionManager;
9596
}
9697

9798
/**
9899
* Set the {@link JmsProperties} to use.
99100
* @param jmsProperties the {@link JmsProperties}
100101
*/
101-
void setJmsProperties(JmsProperties jmsProperties) {
102+
void setJmsProperties(@Nullable JmsProperties jmsProperties) {
102103
this.jmsProperties = jmsProperties;
103104
}
104105

105106
/**
106107
* Set the {@link ObservationRegistry} to use.
107108
* @param observationRegistry the {@link ObservationRegistry}
108109
*/
109-
void setObservationRegistry(ObservationRegistry observationRegistry) {
110+
void setObservationRegistry(@Nullable ObservationRegistry observationRegistry) {
110111
this.observationRegistry = observationRegistry;
111112
}
112113

@@ -119,6 +120,7 @@ void setObservationRegistry(ObservationRegistry observationRegistry) {
119120
public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFactory connectionFactory) {
120121
Assert.notNull(factory, "'factory' must not be null");
121122
Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
123+
Assert.state(this.jmsProperties != null, "'jmsProperties' must not be null");
122124
JmsProperties.Listener listenerProperties = this.jmsProperties.getListener();
123125
Session sessionProperties = listenerProperties.getSession();
124126
factory.setConnectionFactory(connectionFactory);

module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import jakarta.jms.ConnectionFactory;
2222
import jakarta.jms.Message;
23+
import org.jspecify.annotations.Nullable;
2324

2425
import org.springframework.aot.hint.ExecutableMode;
2526
import org.springframework.aot.hint.RuntimeHints;
@@ -56,7 +57,7 @@ public final class JmsAutoConfiguration {
5657
static class JmsRuntimeHints implements RuntimeHintsRegistrar {
5758

5859
@Override
59-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
60+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
6061
hints.reflection()
6162
.registerType(TypeReference.of(AcknowledgeMode.class), (type) -> type.withMethod("of",
6263
List.of(TypeReference.of(String.class)), ExecutableMode.INVOKE));

0 commit comments

Comments
 (0)