diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyRabbitConfiguration.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyRabbitConfiguration.kt index 902b7c4f268..4f1c80f3866 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyRabbitConfiguration.kt +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyRabbitConfiguration.kt @@ -17,6 +17,7 @@ package org.springframework.boot.docs.messaging.amqp.receiving.custom import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory import org.springframework.amqp.rabbit.connection.ConnectionFactory import org.springframework.boot.amqp.autoconfigure.SimpleRabbitListenerContainerFactoryConfigurer import org.springframework.context.annotation.Bean @@ -34,8 +35,8 @@ class MyRabbitConfiguration { return factory } - fun getCustomConnectionFactory() : ConnectionFactory? { - return /**/ null + fun getCustomConnectionFactory() : ConnectionFactory { + return /**/ CachingConnectionFactory() } } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/AbstractConnectionFactoryConfigurer.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/AbstractConnectionFactoryConfigurer.java index dabc7b4e3ae..e60173fe7e1 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/AbstractConnectionFactoryConfigurer.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/AbstractConnectionFactoryConfigurer.java @@ -18,6 +18,8 @@ package org.springframework.boot.amqp.autoconfigure; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionNameStrategy; import org.springframework.boot.context.properties.PropertyMapper; @@ -37,7 +39,7 @@ public abstract class AbstractConnectionFactoryConfigurer> { - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; - private MessageRecoverer messageRecoverer; + private @Nullable MessageRecoverer messageRecoverer; - private List retryTemplateCustomizers; + private @Nullable List retryTemplateCustomizers; private final RabbitProperties rabbitProperties; - private Executor taskExecutor; + private @Nullable Executor taskExecutor; /** * Creates a new configurer that will use the given {@code rabbitProperties}. @@ -63,7 +65,7 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer retryTemplateCustomizers) { + protected void setRetryTemplateCustomizers(@Nullable List retryTemplateCustomizers) { this.retryTemplateCustomizers = retryTemplateCustomizers; } @@ -87,7 +89,7 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer addresses; + private @Nullable List addresses; /** * Mode used to shuffle configured addresses. @@ -106,7 +108,7 @@ public class RabbitProperties { * seconds will be used. */ @DurationUnit(ChronoUnit.SECONDS) - private Duration requestedHeartbeat; + private @Nullable Duration requestedHeartbeat; /** * Number of channels per connection requested by the client. Use 0 for unlimited. @@ -121,12 +123,12 @@ public class RabbitProperties { /** * Type of publisher confirms to use. */ - private ConfirmType publisherConfirmType; + private @Nullable ConfirmType publisherConfirmType; /** * Connection timeout. Set it to zero to wait forever. */ - private Duration connectionTimeout; + private @Nullable Duration connectionTimeout; /** * Continuation timeout for RPC calls in channels. Set it to zero to wait forever. @@ -152,7 +154,7 @@ public class RabbitProperties { private final Stream stream = new Stream(); - private List
parsedAddresses; + private @Nullable List
parsedAddresses; public String getHost() { return this.host; @@ -176,7 +178,7 @@ public class RabbitProperties { this.host = host; } - public Integer getPort() { + public @Nullable Integer getPort() { return this.port; } @@ -198,11 +200,11 @@ public class RabbitProperties { return this.parsedAddresses.get(0).port; } - public void setPort(Integer port) { + public void setPort(@Nullable Integer port) { this.port = port; } - public List getAddresses() { + public @Nullable List getAddresses() { return this.addresses; } @@ -273,7 +275,7 @@ public class RabbitProperties { * @see #setAddresses(List) * @see #getPassword() */ - public String determinePassword() { + public @Nullable String determinePassword() { if (CollectionUtils.isEmpty(this.parsedAddresses)) { return getPassword(); } @@ -289,7 +291,7 @@ public class RabbitProperties { return this.ssl; } - public String getVirtualHost() { + public @Nullable String getVirtualHost() { return this.virtualHost; } @@ -300,7 +302,7 @@ public class RabbitProperties { * @see #setAddresses(List) * @see #getVirtualHost() */ - public String determineVirtualHost() { + public @Nullable String determineVirtualHost() { if (CollectionUtils.isEmpty(this.parsedAddresses)) { return getVirtualHost(); } @@ -308,7 +310,7 @@ public class RabbitProperties { return (address.virtualHost != null) ? address.virtualHost : getVirtualHost(); } - public void setVirtualHost(String virtualHost) { + public void setVirtualHost(@Nullable String virtualHost) { this.virtualHost = StringUtils.hasText(virtualHost) ? virtualHost : "/"; } @@ -320,11 +322,11 @@ public class RabbitProperties { this.addressShuffleMode = addressShuffleMode; } - public Duration getRequestedHeartbeat() { + public @Nullable Duration getRequestedHeartbeat() { return this.requestedHeartbeat; } - public void setRequestedHeartbeat(Duration requestedHeartbeat) { + public void setRequestedHeartbeat(@Nullable Duration requestedHeartbeat) { this.requestedHeartbeat = requestedHeartbeat; } @@ -344,19 +346,19 @@ public class RabbitProperties { this.publisherReturns = publisherReturns; } - public Duration getConnectionTimeout() { + public @Nullable Duration getConnectionTimeout() { return this.connectionTimeout; } - public void setPublisherConfirmType(ConfirmType publisherConfirmType) { + public void setPublisherConfirmType(@Nullable ConfirmType publisherConfirmType) { this.publisherConfirmType = publisherConfirmType; } - public ConfirmType getPublisherConfirmType() { + public @Nullable ConfirmType getPublisherConfirmType() { return this.publisherConfirmType; } - public void setConnectionTimeout(Duration connectionTimeout) { + public void setConnectionTimeout(@Nullable Duration connectionTimeout) { this.connectionTimeout = connectionTimeout; } @@ -400,17 +402,17 @@ public class RabbitProperties { * Whether to enable SSL support. Determined automatically if an address is * provided with the protocol (amqp:// vs. amqps://). */ - private Boolean enabled; + private @Nullable Boolean enabled; /** * SSL bundle name. */ - private String bundle; + private @Nullable String bundle; /** * Path to the key store that holds the SSL certificate. */ - private String keyStore; + private @Nullable String keyStore; /** * Key store type. @@ -420,7 +422,7 @@ public class RabbitProperties { /** * Password used to access the key store. */ - private String keyStorePassword; + private @Nullable String keyStorePassword; /** * Key store algorithm. @@ -430,7 +432,7 @@ public class RabbitProperties { /** * Trust store that holds SSL certificates. */ - private String trustStore; + private @Nullable String trustStore; /** * Trust store type. @@ -440,7 +442,7 @@ public class RabbitProperties { /** * Password used to access the trust store. */ - private String trustStorePassword; + private @Nullable String trustStorePassword; /** * Trust store algorithm. @@ -450,7 +452,7 @@ public class RabbitProperties { /** * SSL algorithm to use. By default, configured by the Rabbit client library. */ - private String algorithm; + private @Nullable String algorithm; /** * Whether to enable server side certificate validation. @@ -462,7 +464,7 @@ public class RabbitProperties { */ private boolean verifyHostname = true; - public Boolean getEnabled() { + public @Nullable Boolean getEnabled() { return this.enabled; } @@ -482,23 +484,23 @@ public class RabbitProperties { return address.determineSslEnabled(defaultEnabled); } - public void setEnabled(Boolean enabled) { + public void setEnabled(@Nullable Boolean enabled) { this.enabled = enabled; } - public String getBundle() { + public @Nullable String getBundle() { return this.bundle; } - public void setBundle(String bundle) { + public void setBundle(@Nullable String bundle) { this.bundle = bundle; } - public String getKeyStore() { + public @Nullable String getKeyStore() { return this.keyStore; } - public void setKeyStore(String keyStore) { + public void setKeyStore(@Nullable String keyStore) { this.keyStore = keyStore; } @@ -510,11 +512,11 @@ public class RabbitProperties { this.keyStoreType = keyStoreType; } - public String getKeyStorePassword() { + public @Nullable String getKeyStorePassword() { return this.keyStorePassword; } - public void setKeyStorePassword(String keyStorePassword) { + public void setKeyStorePassword(@Nullable String keyStorePassword) { this.keyStorePassword = keyStorePassword; } @@ -526,11 +528,11 @@ public class RabbitProperties { this.keyStoreAlgorithm = keyStoreAlgorithm; } - public String getTrustStore() { + public @Nullable String getTrustStore() { return this.trustStore; } - public void setTrustStore(String trustStore) { + public void setTrustStore(@Nullable String trustStore) { this.trustStore = trustStore; } @@ -542,11 +544,11 @@ public class RabbitProperties { this.trustStoreType = trustStoreType; } - public String getTrustStorePassword() { + public @Nullable String getTrustStorePassword() { return this.trustStorePassword; } - public void setTrustStorePassword(String trustStorePassword) { + public void setTrustStorePassword(@Nullable String trustStorePassword) { this.trustStorePassword = trustStorePassword; } @@ -558,11 +560,11 @@ public class RabbitProperties { this.trustStoreAlgorithm = trustStoreAlgorithm; } - public String getAlgorithm() { + public @Nullable String getAlgorithm() { return this.algorithm; } - public void setAlgorithm(String sslAlgorithm) { + public void setAlgorithm(@Nullable String sslAlgorithm) { this.algorithm = sslAlgorithm; } @@ -604,27 +606,27 @@ public class RabbitProperties { * Number of channels to retain in the cache. When "check-timeout" > 0, max * channels per connection. */ - private Integer size; + private @Nullable Integer size; /** * Duration to wait to obtain a channel if the cache size has been reached. If * 0, always create a new channel. */ - private Duration checkoutTimeout; + private @Nullable Duration checkoutTimeout; - public Integer getSize() { + public @Nullable Integer getSize() { return this.size; } - public void setSize(Integer size) { + public void setSize(@Nullable Integer size) { this.size = size; } - public Duration getCheckoutTimeout() { + public @Nullable Duration getCheckoutTimeout() { return this.checkoutTimeout; } - public void setCheckoutTimeout(Duration checkoutTimeout) { + public void setCheckoutTimeout(@Nullable Duration checkoutTimeout) { this.checkoutTimeout = checkoutTimeout; } @@ -640,7 +642,7 @@ public class RabbitProperties { /** * Number of connections to cache. Only applies when mode is CONNECTION. */ - private Integer size; + private @Nullable Integer size; public CacheMode getMode() { return this.mode; @@ -650,11 +652,11 @@ public class RabbitProperties { this.mode = mode; } - public Integer getSize() { + public @Nullable Integer getSize() { return this.size; } - public void setSize(Integer size) { + public void setSize(@Nullable Integer size) { this.size = size; } @@ -744,23 +746,23 @@ public class RabbitProperties { /** * Acknowledge mode of container. */ - private AcknowledgeMode acknowledgeMode; + private @Nullable AcknowledgeMode acknowledgeMode; /** * Maximum number of unacknowledged messages that can be outstanding at each * consumer. */ - private Integer prefetch; + private @Nullable Integer prefetch; /** * Whether rejected deliveries are re-queued by default. */ - private Boolean defaultRequeueRejected; + private @Nullable Boolean defaultRequeueRejected; /** * How often idle container events should be published. */ - private Duration idleEventInterval; + private @Nullable Duration idleEventInterval; /** * Whether the container should present batched messages as discrete messages or @@ -787,35 +789,35 @@ public class RabbitProperties { this.autoStartup = autoStartup; } - public AcknowledgeMode getAcknowledgeMode() { + public @Nullable AcknowledgeMode getAcknowledgeMode() { return this.acknowledgeMode; } - public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) { + public void setAcknowledgeMode(@Nullable AcknowledgeMode acknowledgeMode) { this.acknowledgeMode = acknowledgeMode; } - public Integer getPrefetch() { + public @Nullable Integer getPrefetch() { return this.prefetch; } - public void setPrefetch(Integer prefetch) { + public void setPrefetch(@Nullable Integer prefetch) { this.prefetch = prefetch; } - public Boolean getDefaultRequeueRejected() { + public @Nullable Boolean getDefaultRequeueRejected() { return this.defaultRequeueRejected; } - public void setDefaultRequeueRejected(Boolean defaultRequeueRejected) { + public void setDefaultRequeueRejected(@Nullable Boolean defaultRequeueRejected) { this.defaultRequeueRejected = defaultRequeueRejected; } - public Duration getIdleEventInterval() { + public @Nullable Duration getIdleEventInterval() { return this.idleEventInterval; } - public void setIdleEventInterval(Duration idleEventInterval) { + public void setIdleEventInterval(@Nullable Duration idleEventInterval) { this.idleEventInterval = idleEventInterval; } @@ -851,18 +853,18 @@ public class RabbitProperties { /** * Minimum number of listener invoker threads. */ - private Integer concurrency; + private @Nullable Integer concurrency; /** * Maximum number of listener invoker threads. */ - private Integer maxConcurrency; + private @Nullable Integer maxConcurrency; /** * Batch size, expressed as the number of physical messages, to be used by the * container. */ - private Integer batchSize; + private @Nullable Integer batchSize; /** * Whether to fail if the queues declared by the container are not available on @@ -879,27 +881,27 @@ public class RabbitProperties { */ private boolean consumerBatchEnabled; - public Integer getConcurrency() { + public @Nullable Integer getConcurrency() { return this.concurrency; } - public void setConcurrency(Integer concurrency) { + public void setConcurrency(@Nullable Integer concurrency) { this.concurrency = concurrency; } - 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 Integer getBatchSize() { + public @Nullable Integer getBatchSize() { return this.batchSize; } - public void setBatchSize(Integer batchSize) { + public void setBatchSize(@Nullable Integer batchSize) { this.batchSize = batchSize; } @@ -930,7 +932,7 @@ public class RabbitProperties { /** * Number of consumers per queue. */ - private Integer consumersPerQueue; + private @Nullable Integer consumersPerQueue; /** * Whether to fail if the queues declared by the container are not available on @@ -938,11 +940,11 @@ public class RabbitProperties { */ private boolean missingQueuesFatal = false; - public Integer getConsumersPerQueue() { + public @Nullable Integer getConsumersPerQueue() { return this.consumersPerQueue; } - public void setConsumersPerQueue(Integer consumersPerQueue) { + public void setConsumersPerQueue(@Nullable Integer consumersPerQueue) { this.consumersPerQueue = consumersPerQueue; } @@ -982,17 +984,17 @@ public class RabbitProperties { /** * Whether to enable mandatory messages. */ - private Boolean mandatory; + private @Nullable Boolean mandatory; /** * Timeout for receive() operations. */ - private Duration receiveTimeout; + private @Nullable Duration receiveTimeout; /** * Timeout for sendAndReceive() operations. */ - private Duration replyTimeout; + private @Nullable Duration replyTimeout; /** * Name of the default exchange to use for send operations. @@ -1008,7 +1010,7 @@ public class RabbitProperties { * Name of the default queue to receive messages from when none is specified * explicitly. */ - private String defaultReceiveQueue; + private @Nullable String defaultReceiveQueue; /** * Whether to enable observation. @@ -1018,33 +1020,33 @@ public class RabbitProperties { /** * Simple patterns for allowable packages/classes for deserialization. */ - private List allowedListPatterns; + private @Nullable List allowedListPatterns; public Retry getRetry() { return this.retry; } - public Boolean getMandatory() { + public @Nullable Boolean getMandatory() { return this.mandatory; } - public void setMandatory(Boolean mandatory) { + public void setMandatory(@Nullable Boolean mandatory) { this.mandatory = mandatory; } - public Duration getReceiveTimeout() { + public @Nullable Duration getReceiveTimeout() { return this.receiveTimeout; } - public void setReceiveTimeout(Duration receiveTimeout) { + public void setReceiveTimeout(@Nullable Duration receiveTimeout) { this.receiveTimeout = receiveTimeout; } - public Duration getReplyTimeout() { + public @Nullable Duration getReplyTimeout() { return this.replyTimeout; } - public void setReplyTimeout(Duration replyTimeout) { + public void setReplyTimeout(@Nullable Duration replyTimeout) { this.replyTimeout = replyTimeout; } @@ -1064,11 +1066,11 @@ public class RabbitProperties { this.routingKey = routingKey; } - public String getDefaultReceiveQueue() { + public @Nullable String getDefaultReceiveQueue() { return this.defaultReceiveQueue; } - public void setDefaultReceiveQueue(String defaultReceiveQueue) { + public void setDefaultReceiveQueue(@Nullable String defaultReceiveQueue) { this.defaultReceiveQueue = defaultReceiveQueue; } @@ -1080,11 +1082,11 @@ public class RabbitProperties { this.observationEnabled = observationEnabled; } - public List getAllowedListPatterns() { + public @Nullable List getAllowedListPatterns() { return this.allowedListPatterns; } - public void setAllowedListPatterns(List allowedListPatterns) { + public void setAllowedListPatterns(@Nullable List allowedListPatterns) { this.allowedListPatterns = allowedListPatterns; } @@ -1186,13 +1188,13 @@ public class RabbitProperties { private int port; - private String username; + private @Nullable String username; - private String password; + private @Nullable String password; - private String virtualHost; + private @Nullable String virtualHost; - private Boolean secureConnection; + private @Nullable Boolean secureConnection; private Address(String input, boolean sslEnabled) { input = input.trim(); @@ -1278,24 +1280,24 @@ public class RabbitProperties { * Virtual host of a RabbitMQ instance with the Stream plugin enabled. When not * set, spring.rabbitmq.virtual-host is used. */ - private String virtualHost; + private @Nullable String virtualHost; /** * Login user to authenticate to the broker. When not set, * spring.rabbitmq.username is used. */ - private String username; + private @Nullable String username; /** * Login password to authenticate to the broker. When not set * spring.rabbitmq.password is used. */ - private String password; + private @Nullable String password; /** * Name of the stream. */ - private String name; + private @Nullable String name; public String getHost() { return this.host; @@ -1313,35 +1315,35 @@ public class RabbitProperties { this.port = port; } - public String getVirtualHost() { + public @Nullable String getVirtualHost() { return this.virtualHost; } - public void setVirtualHost(String virtualHost) { + public void setVirtualHost(@Nullable String virtualHost) { this.virtualHost = virtualHost; } - public String getUsername() { + public @Nullable String getUsername() { return this.username; } - public void setUsername(String username) { + public void setUsername(@Nullable String username) { this.username = username; } - public String getPassword() { + public @Nullable String getPassword() { return this.password; } - public void setPassword(String password) { + public void setPassword(@Nullable String password) { this.password = password; } - public String getName() { + public @Nullable String getName() { return this.name; } - public void setName(String name) { + public void setName(@Nullable String name) { this.name = name; } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamConfiguration.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamConfiguration.java index f59f0461c47..8fe7365af35 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamConfiguration.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamConfiguration.java @@ -39,6 +39,7 @@ import org.springframework.rabbit.stream.producer.ProducerCustomizer; import org.springframework.rabbit.stream.producer.RabbitStreamOperations; import org.springframework.rabbit.stream.producer.RabbitStreamTemplate; import org.springframework.rabbit.stream.support.converter.StreamMessageConverter; +import org.springframework.util.Assert; /** * Configuration for Spring RabbitMQ Stream plugin support. @@ -93,8 +94,9 @@ class RabbitStreamConfiguration { @ConditionalOnProperty(name = "spring.rabbitmq.stream.name") RabbitStreamTemplate rabbitStreamTemplate(Environment rabbitStreamEnvironment, RabbitProperties properties, RabbitStreamTemplateConfigurer configurer) { - RabbitStreamTemplate template = new RabbitStreamTemplate(rabbitStreamEnvironment, - properties.getStream().getName()); + String name = properties.getStream().getName(); + Assert.state(name != null, "'name' must not be null"); + RabbitStreamTemplate template = new RabbitStreamTemplate(rabbitStreamEnvironment, name); configurer.configure(template); return template; } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamTemplateConfigurer.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamTemplateConfigurer.java index 58f2b9a2cf6..6fb5519ab6a 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamTemplateConfigurer.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitStreamTemplateConfigurer.java @@ -16,6 +16,8 @@ package org.springframework.boot.amqp.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.rabbit.stream.producer.ProducerCustomizer; import org.springframework.rabbit.stream.producer.RabbitStreamTemplate; @@ -33,18 +35,18 @@ import org.springframework.rabbit.stream.support.converter.StreamMessageConverte */ public class RabbitStreamTemplateConfigurer { - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; - private StreamMessageConverter streamMessageConverter; + private @Nullable StreamMessageConverter streamMessageConverter; - private ProducerCustomizer producerCustomizer; + private @Nullable ProducerCustomizer producerCustomizer; /** * Set the {@link MessageConverter} to use or {@code null} if the out-of-the-box * converter should be used. * @param messageConverter the {@link MessageConverter} */ - public void setMessageConverter(MessageConverter messageConverter) { + public void setMessageConverter(@Nullable MessageConverter messageConverter) { this.messageConverter = messageConverter; } @@ -53,7 +55,7 @@ public class RabbitStreamTemplateConfigurer { * stream message converter should be used. * @param streamMessageConverter the {@link StreamMessageConverter} */ - public void setStreamMessageConverter(StreamMessageConverter streamMessageConverter) { + public void setStreamMessageConverter(@Nullable StreamMessageConverter streamMessageConverter) { this.streamMessageConverter = streamMessageConverter; } @@ -61,7 +63,7 @@ public class RabbitStreamTemplateConfigurer { * Set the {@link ProducerCustomizer} instances to use. * @param producerCustomizer the producer customizer */ - public void setProducerCustomizer(ProducerCustomizer producerCustomizer) { + public void setProducerCustomizer(@Nullable ProducerCustomizer producerCustomizer) { this.producerCustomizer = producerCustomizer; } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitTemplateConfigurer.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitTemplateConfigurer.java index a8af90eba1a..24545d18e7a 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitTemplateConfigurer.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitTemplateConfigurer.java @@ -19,6 +19,8 @@ package org.springframework.boot.amqp.autoconfigure; import java.time.Duration; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter; @@ -42,9 +44,9 @@ import org.springframework.util.CollectionUtils; */ public class RabbitTemplateConfigurer { - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; - private List retryTemplateCustomizers; + private @Nullable List retryTemplateCustomizers; private final RabbitProperties rabbitProperties; @@ -62,7 +64,7 @@ public class RabbitTemplateConfigurer { * converter should be used. * @param messageConverter the {@link MessageConverter} */ - public void setMessageConverter(MessageConverter messageConverter) { + public void setMessageConverter(@Nullable MessageConverter messageConverter) { this.messageConverter = messageConverter; } @@ -70,7 +72,7 @@ public class RabbitTemplateConfigurer { * Set the {@link RabbitRetryTemplateCustomizer} instances to use. * @param retryTemplateCustomizers the retry template customizers */ - public void setRetryTemplateCustomizers(List retryTemplateCustomizers) { + public void setRetryTemplateCustomizers(@Nullable List retryTemplateCustomizers) { this.retryTemplateCustomizers = retryTemplateCustomizers; } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RetryTemplateFactory.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RetryTemplateFactory.java index 577233599a4..c06294ae372 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RetryTemplateFactory.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RetryTemplateFactory.java @@ -19,6 +19,8 @@ package org.springframework.boot.amqp.autoconfigure; import java.time.Duration; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.retry.backoff.ExponentialBackOffPolicy; import org.springframework.retry.policy.SimpleRetryPolicy; @@ -32,9 +34,9 @@ import org.springframework.retry.support.RetryTemplate; */ class RetryTemplateFactory { - private final List customizers; + private final @Nullable List customizers; - RetryTemplateFactory(List customizers) { + RetryTemplateFactory(@Nullable List customizers) { this.customizers = customizers; } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/SslBundleRabbitConnectionFactoryBean.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/SslBundleRabbitConnectionFactoryBean.java index 243938c1de9..ae2345fb06b 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/SslBundleRabbitConnectionFactoryBean.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/SslBundleRabbitConnectionFactoryBean.java @@ -16,6 +16,8 @@ package org.springframework.boot.amqp.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean; import org.springframework.boot.ssl.SslBundle; @@ -27,7 +29,7 @@ import org.springframework.boot.ssl.SslBundle; */ class SslBundleRabbitConnectionFactoryBean extends RabbitConnectionFactoryBean { - private SslBundle sslBundle; + private @Nullable SslBundle sslBundle; private boolean enableHostnameVerification; @@ -44,7 +46,7 @@ class SslBundleRabbitConnectionFactoryBean extends RabbitConnectionFactoryBean { } } - void setSslBundle(SslBundle sslBundle) { + void setSslBundle(@Nullable SslBundle sslBundle) { this.sslBundle = sslBundle; } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/health/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/health/package-info.java index 6eaf5d43bd1..bbd0d5e86d3 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/health/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/health/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for RabbitMQ health. */ +@NullMarked package org.springframework.boot.amqp.autoconfigure.health; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/RabbitConnectionFactoryMetricsPostProcessor.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/RabbitConnectionFactoryMetricsPostProcessor.java index 651a451cc7d..fa36c3d34af 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/RabbitConnectionFactoryMetricsPostProcessor.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/RabbitConnectionFactoryMetricsPostProcessor.java @@ -20,6 +20,7 @@ import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.MetricsCollector; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; +import org.jspecify.annotations.Nullable; import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -41,7 +42,7 @@ class RabbitConnectionFactoryMetricsPostProcessor implements BeanPostProcessor, private final ApplicationContext context; - private volatile MeterRegistry meterRegistry; + private volatile @Nullable MeterRegistry meterRegistry; RabbitConnectionFactoryMetricsPostProcessor(ApplicationContext context) { this.context = context; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/package-info.java index 7e04a5a18be..ab0814c6f72 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/metrics/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for RabbitMQ metrics. */ +@NullMarked package org.springframework.boot.amqp.autoconfigure.metrics; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/package-info.java index 2bc9284570c..b519c35a2ca 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for RabbitMQ. */ +@NullMarked package org.springframework.boot.amqp.autoconfigure; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/docker/compose/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/docker/compose/package-info.java index df1e3ade8b7..c2d355c0797 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/docker/compose/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/docker/compose/package-info.java @@ -17,4 +17,7 @@ /** * Support for Docker Compose RabbitMQ service connections. */ +@NullMarked package org.springframework.boot.amqp.docker.compose; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/RabbitHealthIndicator.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/RabbitHealthIndicator.java index 8f0b9a91165..f11e80594c4 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/RabbitHealthIndicator.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/RabbitHealthIndicator.java @@ -16,6 +16,8 @@ package org.springframework.boot.amqp.health; +import org.jspecify.annotations.Nullable; + import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.boot.health.contributor.AbstractHealthIndicator; import org.springframework.boot.health.contributor.Health; @@ -44,9 +46,12 @@ public class RabbitHealthIndicator extends AbstractHealthIndicator { builder.up().withDetail("version", getVersion()); } - private String getVersion() { - return this.rabbitTemplate - .execute((channel) -> channel.getConnection().getServerProperties().get("version").toString()); + private @Nullable String getVersion() { + return this.rabbitTemplate.execute((channel) -> { + Object version = channel.getConnection().getServerProperties().get("version"); + Assert.state(version != null, "'version' must not be null"); + return version.toString(); + }); } } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/package-info.java index cacab20fb2a..ecb6ea0b164 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/package-info.java @@ -17,4 +17,7 @@ /** * Health integration for AMQP and RabbitMQ. */ +@NullMarked package org.springframework.boot.amqp.health; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/RabbitMetrics.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/RabbitMetrics.java index 799e0195038..20ae4111b16 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/RabbitMetrics.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/RabbitMetrics.java @@ -23,6 +23,7 @@ import com.rabbitmq.client.impl.MicrometerMetricsCollector; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.binder.MeterBinder; +import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; @@ -44,7 +45,7 @@ public class RabbitMetrics implements MeterBinder { * @param connectionFactory the {@link ConnectionFactory} to instrument * @param tags tags to apply to all recorded metrics */ - public RabbitMetrics(ConnectionFactory connectionFactory, Iterable tags) { + public RabbitMetrics(ConnectionFactory connectionFactory, @Nullable Iterable tags) { Assert.notNull(connectionFactory, "'connectionFactory' must not be null"); this.connectionFactory = connectionFactory; this.tags = (tags != null) ? tags : Collections.emptyList(); diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/package-info.java index 645c30fb49b..e63026906cd 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/metrics/package-info.java @@ -17,4 +17,7 @@ /** * Metrics for AMQP and RabbitMQ. */ +@NullMarked package org.springframework.boot.amqp.metrics; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/RabbitContainerConnectionDetailsFactory.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/RabbitContainerConnectionDetailsFactory.java index 54702a1e9c2..ec74a57c491 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/RabbitContainerConnectionDetailsFactory.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/RabbitContainerConnectionDetailsFactory.java @@ -19,6 +19,7 @@ package org.springframework.boot.amqp.testcontainers; import java.net.URI; import java.util.List; +import org.jspecify.annotations.Nullable; import org.testcontainers.containers.RabbitMQContainer; import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails; @@ -72,7 +73,7 @@ class RabbitContainerConnectionDetailsFactory } @Override - public SslBundle getSslBundle() { + public @Nullable SslBundle getSslBundle() { return super.getSslBundle(); } diff --git a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/package-info.java b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/package-info.java index f4eed1ef104..69c6364ef32 100644 --- a/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/package-info.java +++ b/module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/testcontainers/package-info.java @@ -17,4 +17,7 @@ /** * Support for testcontainers RabbitMQ service connections. */ +@NullMarked package org.springframework.boot.amqp.testcontainers; + +import org.jspecify.annotations.NullMarked;