diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.kt index 4205f4ee862..b4c74768731 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.kt +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.kt @@ -28,7 +28,7 @@ import org.springframework.jms.config.DefaultJmsListenerContainerFactory class MyJmsConfiguration { @Bean - fun jmsListenerContainerFactory(connectionFactory: ConnectionFactory?, + fun jmsListenerContainerFactory(connectionFactory: ConnectionFactory, configurer: DefaultJmsListenerContainerFactoryConfigurer): DefaultJmsListenerContainerFactory { val listenerFactory = DefaultJmsListenerContainerFactory() configurer.configure(listenerFactory, ConnectionFactoryUnwrapper.unwrapCaching(connectionFactory)) diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java index 72f061346bc..154776c121f 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java @@ -17,6 +17,7 @@ package org.springframework.boot.jms; import jakarta.jms.ConnectionFactory; +import org.jspecify.annotations.Nullable; import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; import org.springframework.jms.connection.CachingConnectionFactory; @@ -57,7 +58,7 @@ public final class ConnectionFactoryUnwrapper { * @param connectionFactory a connection factory * @return the native connection factory that it wraps, if any */ - public static ConnectionFactory unwrap(ConnectionFactory connectionFactory) { + public static @Nullable ConnectionFactory unwrap(@Nullable ConnectionFactory connectionFactory) { if (connectionFactory instanceof CachingConnectionFactory cachingConnectionFactory) { return unwrap(cachingConnectionFactory.getTargetConnectionFactory()); } @@ -65,7 +66,8 @@ public final class ConnectionFactoryUnwrapper { return (unwrapedConnectionFactory != null) ? unwrap(unwrapedConnectionFactory) : connectionFactory; } - private static ConnectionFactory unwrapFromJmsPoolConnectionFactory(ConnectionFactory connectionFactory) { + private static @Nullable ConnectionFactory unwrapFromJmsPoolConnectionFactory( + @Nullable ConnectionFactory connectionFactory) { try { if (connectionFactory instanceof JmsPoolConnectionFactory jmsPoolConnectionFactory) { return (ConnectionFactory) jmsPoolConnectionFactory.getConnectionFactory(); diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/DefaultJmsListenerContainerFactoryConfigurer.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/DefaultJmsListenerContainerFactoryConfigurer.java index 02eaeb1f8f7..9fcc81c40f7 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/DefaultJmsListenerContainerFactoryConfigurer.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/DefaultJmsListenerContainerFactoryConfigurer.java @@ -21,6 +21,7 @@ import java.time.Duration; import io.micrometer.observation.ObservationRegistry; import jakarta.jms.ConnectionFactory; import jakarta.jms.ExceptionListener; +import org.jspecify.annotations.Nullable; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.jms.autoconfigure.JmsProperties.Listener.Session; @@ -46,24 +47,24 @@ import org.springframework.util.Assert; */ public final class DefaultJmsListenerContainerFactoryConfigurer { - private DestinationResolver destinationResolver; + private @Nullable DestinationResolver destinationResolver; - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; - private ExceptionListener exceptionListener; + private @Nullable ExceptionListener exceptionListener; - private JtaTransactionManager transactionManager; + private @Nullable JtaTransactionManager transactionManager; - private JmsProperties jmsProperties; + private @Nullable JmsProperties jmsProperties; - private ObservationRegistry observationRegistry; + private @Nullable ObservationRegistry observationRegistry; /** * Set the {@link DestinationResolver} to use or {@code null} if no destination * resolver should be associated with the factory by default. * @param destinationResolver the {@link DestinationResolver} */ - void setDestinationResolver(DestinationResolver destinationResolver) { + void setDestinationResolver(@Nullable DestinationResolver destinationResolver) { this.destinationResolver = destinationResolver; } @@ -72,7 +73,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { * converter should be used. * @param messageConverter the {@link MessageConverter} */ - void setMessageConverter(MessageConverter messageConverter) { + void setMessageConverter(@Nullable MessageConverter messageConverter) { this.messageConverter = messageConverter; } @@ -81,7 +82,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { * should be associated by default. * @param exceptionListener the {@link ExceptionListener} */ - void setExceptionListener(ExceptionListener exceptionListener) { + void setExceptionListener(@Nullable ExceptionListener exceptionListener) { this.exceptionListener = exceptionListener; } @@ -90,7 +91,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { * should not be used. * @param transactionManager the {@link JtaTransactionManager} */ - void setTransactionManager(JtaTransactionManager transactionManager) { + void setTransactionManager(@Nullable JtaTransactionManager transactionManager) { this.transactionManager = transactionManager; } @@ -98,7 +99,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { * Set the {@link JmsProperties} to use. * @param jmsProperties the {@link JmsProperties} */ - void setJmsProperties(JmsProperties jmsProperties) { + void setJmsProperties(@Nullable JmsProperties jmsProperties) { this.jmsProperties = jmsProperties; } @@ -106,7 +107,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { * Set the {@link ObservationRegistry} to use. * @param observationRegistry the {@link ObservationRegistry} */ - void setObservationRegistry(ObservationRegistry observationRegistry) { + void setObservationRegistry(@Nullable ObservationRegistry observationRegistry) { this.observationRegistry = observationRegistry; } @@ -119,6 +120,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFactory connectionFactory) { Assert.notNull(factory, "'factory' must not be null"); Assert.notNull(connectionFactory, "'connectionFactory' must not be null"); + Assert.state(this.jmsProperties != null, "'jmsProperties' must not be null"); JmsProperties.Listener listenerProperties = this.jmsProperties.getListener(); Session sessionProperties = listenerProperties.getSession(); factory.setConnectionFactory(connectionFactory); diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsAutoConfiguration.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsAutoConfiguration.java index 4d8329f1b81..783a422384c 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsAutoConfiguration.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsAutoConfiguration.java @@ -20,6 +20,7 @@ import java.util.List; import jakarta.jms.ConnectionFactory; import jakarta.jms.Message; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; @@ -56,7 +57,7 @@ public final class JmsAutoConfiguration { static class JmsRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.reflection() .registerType(TypeReference.of(AcknowledgeMode.class), (type) -> type.withMethod("of", List.of(TypeReference.of(String.class)), ExecutableMode.INVOKE)); diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsProperties.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsProperties.java index 983ce4d3593..0ac4f513719 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsProperties.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsProperties.java @@ -18,6 +18,8 @@ package org.springframework.boot.jms.autoconfigure; import java.time.Duration; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -42,7 +44,7 @@ public class JmsProperties { * Connection factory JNDI name. When set, takes precedence to others connection * factory auto-configurations. */ - private String jndiName; + private @Nullable String jndiName; /** * Whether the subscription is durable. @@ -52,7 +54,7 @@ public class JmsProperties { /** * Client id of the connection. */ - private String clientId; + private @Nullable String clientId; private final Cache cache = new Cache(); @@ -76,19 +78,19 @@ public class JmsProperties { this.subscriptionDurable = subscriptionDurable; } - public String getClientId() { + public @Nullable String getClientId() { return this.clientId; } - public void setClientId(String clientId) { + public void setClientId(@Nullable String clientId) { this.clientId = clientId; } - public String getJndiName() { + public @Nullable String getJndiName() { return this.jndiName; } - public void setJndiName(String jndiName) { + public void setJndiName(@Nullable String jndiName) { this.jndiName = jndiName; } @@ -171,12 +173,12 @@ public class JmsProperties { * Minimum number of concurrent consumers. When max-concurrency is not specified * the minimum will also be used as the maximum. */ - private Integer minConcurrency; + private @Nullable Integer minConcurrency; /** * Maximum number of concurrent consumers. */ - private Integer maxConcurrency; + private @Nullable Integer maxConcurrency; /** * Timeout to use for receive calls. Use -1 for a no-wait receive or 0 for no @@ -190,7 +192,7 @@ public class JmsProperties { * a SchedulingTaskExecutor is configured on the listener (10 messages), as it * indicates a preference for short-lived tasks. */ - private Integer maxMessagesPerTask; + private @Nullable Integer maxMessagesPerTask; private final Session session = new Session(); @@ -202,23 +204,23 @@ public class JmsProperties { this.autoStartup = autoStartup; } - public Integer getMinConcurrency() { + public @Nullable Integer getMinConcurrency() { return this.minConcurrency; } - public void setMinConcurrency(Integer minConcurrency) { + public void setMinConcurrency(@Nullable Integer minConcurrency) { this.minConcurrency = minConcurrency; } - public Integer getMaxConcurrency() { + public @Nullable Integer getMaxConcurrency() { return this.maxConcurrency; } - public void setMaxConcurrency(Integer maxConcurrency) { + public void setMaxConcurrency(@Nullable Integer maxConcurrency) { this.maxConcurrency = maxConcurrency; } - public String formatConcurrency() { + public @Nullable String formatConcurrency() { if (this.minConcurrency == null) { return (this.maxConcurrency != null) ? "1-" + this.maxConcurrency : null; } @@ -234,11 +236,11 @@ public class JmsProperties { this.receiveTimeout = receiveTimeout; } - public Integer getMaxMessagesPerTask() { + public @Nullable Integer getMaxMessagesPerTask() { return this.maxMessagesPerTask; } - public void setMaxMessagesPerTask(Integer maxMessagesPerTask) { + public void setMaxMessagesPerTask(@Nullable Integer maxMessagesPerTask) { this.maxMessagesPerTask = maxMessagesPerTask; } @@ -257,7 +259,7 @@ public class JmsProperties { * Whether the listener container should use transacted JMS sessions. Defaults * to false in the presence of a JtaTransactionManager and true otherwise. */ - private Boolean transacted; + private @Nullable Boolean transacted; public AcknowledgeMode getAcknowledgeMode() { return this.acknowledgeMode; @@ -267,11 +269,11 @@ public class JmsProperties { this.acknowledgeMode = acknowledgeMode; } - public Boolean getTransacted() { + public @Nullable Boolean getTransacted() { return this.transacted; } - public void setTransacted(Boolean transacted) { + public void setTransacted(@Nullable Boolean transacted) { this.transacted = transacted; } @@ -285,28 +287,28 @@ public class JmsProperties { * Default destination to use on send and receive operations that do not have a * destination parameter. */ - private String defaultDestination; + private @Nullable String defaultDestination; /** * Delivery delay to use for send calls. */ - private Duration deliveryDelay; + private @Nullable Duration deliveryDelay; /** * Delivery mode. Enables QoS (Quality of Service) when set. */ - private DeliveryMode deliveryMode; + private @Nullable DeliveryMode deliveryMode; /** * Priority of a message when sending. Enables QoS (Quality of Service) when set. */ - private Integer priority; + private @Nullable Integer priority; /** * Time-to-live of a message when sending. Enables QoS (Quality of Service) when * set. */ - private Duration timeToLive; + private @Nullable Duration timeToLive; /** * Whether to enable explicit QoS (Quality of Service) when sending a message. @@ -314,52 +316,52 @@ public class JmsProperties { * used when sending a message. QoS is automatically enabled when at least one of * those settings is customized. */ - private Boolean qosEnabled; + private @Nullable Boolean qosEnabled; /** * Timeout to use for receive calls. */ - private Duration receiveTimeout; + private @Nullable Duration receiveTimeout; private final Session session = new Session(); - public String getDefaultDestination() { + public @Nullable String getDefaultDestination() { return this.defaultDestination; } - public void setDefaultDestination(String defaultDestination) { + public void setDefaultDestination(@Nullable String defaultDestination) { this.defaultDestination = defaultDestination; } - public Duration getDeliveryDelay() { + public @Nullable Duration getDeliveryDelay() { return this.deliveryDelay; } - public void setDeliveryDelay(Duration deliveryDelay) { + public void setDeliveryDelay(@Nullable Duration deliveryDelay) { this.deliveryDelay = deliveryDelay; } - public DeliveryMode getDeliveryMode() { + public @Nullable DeliveryMode getDeliveryMode() { return this.deliveryMode; } - public void setDeliveryMode(DeliveryMode deliveryMode) { + public void setDeliveryMode(@Nullable DeliveryMode deliveryMode) { this.deliveryMode = deliveryMode; } - public Integer getPriority() { + public @Nullable Integer getPriority() { return this.priority; } - public void setPriority(Integer priority) { + public void setPriority(@Nullable Integer priority) { this.priority = priority; } - public Duration getTimeToLive() { + public @Nullable Duration getTimeToLive() { return this.timeToLive; } - public void setTimeToLive(Duration timeToLive) { + public void setTimeToLive(@Nullable Duration timeToLive) { this.timeToLive = timeToLive; } @@ -370,19 +372,19 @@ public class JmsProperties { return (getDeliveryMode() != null || getPriority() != null || getTimeToLive() != null); } - public Boolean getQosEnabled() { + public @Nullable Boolean getQosEnabled() { return this.qosEnabled; } - public void setQosEnabled(Boolean qosEnabled) { + public void setQosEnabled(@Nullable Boolean qosEnabled) { this.qosEnabled = qosEnabled; } - public Duration getReceiveTimeout() { + public @Nullable Duration getReceiveTimeout() { return this.receiveTimeout; } - public void setReceiveTimeout(Duration receiveTimeout) { + public void setReceiveTimeout(@Nullable Duration receiveTimeout) { this.receiveTimeout = receiveTimeout; } diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/health/package-info.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/health/package-info.java index 329a5a0399e..d9db019353e 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/health/package-info.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/health/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for JMS health. */ +@NullMarked package org.springframework.boot.jms.autoconfigure.health; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/package-info.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/package-info.java index 4d7d4a8b980..60254d1d67e 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/package-info.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for JMS. */ +@NullMarked package org.springframework.boot.jms.autoconfigure; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/health/package-info.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/health/package-info.java index 9ce57fb93ad..2d7b0f13d18 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/health/package-info.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/health/package-info.java @@ -17,4 +17,7 @@ /** * Health integration for JMS. */ +@NullMarked package org.springframework.boot.jms.health; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/package-info.java b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/package-info.java index 504fc7c3a3e..eec292394fa 100644 --- a/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/package-info.java +++ b/module/spring-boot-jms/src/main/java/org/springframework/boot/jms/package-info.java @@ -17,4 +17,7 @@ /** * Support for Java Message Service (JMS). */ +@NullMarked package org.springframework.boot.jms; + +import org.jspecify.annotations.NullMarked;