Skip to content

Commit f5dcf51

Browse files
committed
Add nullability annotations to module/spring-boot-amqp
See gh-46587
1 parent 1fb95fb commit f5dcf51

23 files changed

+205
-154
lines changed

documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyRabbitConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.docs.messaging.amqp.receiving.custom
1818

1919
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory
20+
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory
2021
import org.springframework.amqp.rabbit.connection.ConnectionFactory
2122
import org.springframework.boot.amqp.autoconfigure.SimpleRabbitListenerContainerFactoryConfigurer
2223
import org.springframework.context.annotation.Bean
@@ -34,8 +35,8 @@ class MyRabbitConfiguration {
3435
return factory
3536
}
3637

37-
fun getCustomConnectionFactory() : ConnectionFactory? {
38-
return /**/ null
38+
fun getCustomConnectionFactory() : ConnectionFactory {
39+
return /**/ CachingConnectionFactory()
3940
}
4041

4142
}

module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/AbstractConnectionFactoryConfigurer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.stream.Collectors;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory;
2224
import org.springframework.amqp.rabbit.connection.ConnectionNameStrategy;
2325
import org.springframework.boot.context.properties.PropertyMapper;
@@ -37,7 +39,7 @@ public abstract class AbstractConnectionFactoryConfigurer<T extends AbstractConn
3739

3840
private final RabbitProperties rabbitProperties;
3941

40-
private ConnectionNameStrategy connectionNameStrategy;
42+
private @Nullable ConnectionNameStrategy connectionNameStrategy;
4143

4244
private final RabbitConnectionDetails connectionDetails;
4345

@@ -65,11 +67,11 @@ protected AbstractConnectionFactoryConfigurer(RabbitProperties properties,
6567
this.connectionDetails = connectionDetails;
6668
}
6769

68-
protected final ConnectionNameStrategy getConnectionNameStrategy() {
70+
protected final @Nullable ConnectionNameStrategy getConnectionNameStrategy() {
6971
return this.connectionNameStrategy;
7072
}
7173

72-
public final void setConnectionNameStrategy(ConnectionNameStrategy connectionNameStrategy) {
74+
public final void setConnectionNameStrategy(@Nullable ConnectionNameStrategy connectionNameStrategy) {
7375
this.connectionNameStrategy = connectionNameStrategy;
7476
}
7577

module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/AbstractRabbitListenerContainerFactoryConfigurer.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.List;
2020
import java.util.concurrent.Executor;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.amqp.rabbit.config.AbstractRabbitListenerContainerFactory;
2325
import org.springframework.amqp.rabbit.config.RetryInterceptorBuilder;
2426
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
@@ -40,15 +42,15 @@
4042
*/
4143
public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends AbstractRabbitListenerContainerFactory<?>> {
4244

43-
private MessageConverter messageConverter;
45+
private @Nullable MessageConverter messageConverter;
4446

45-
private MessageRecoverer messageRecoverer;
47+
private @Nullable MessageRecoverer messageRecoverer;
4648

47-
private List<RabbitRetryTemplateCustomizer> retryTemplateCustomizers;
49+
private @Nullable List<RabbitRetryTemplateCustomizer> retryTemplateCustomizers;
4850

4951
private final RabbitProperties rabbitProperties;
5052

51-
private Executor taskExecutor;
53+
private @Nullable Executor taskExecutor;
5254

5355
/**
5456
* Creates a new configurer that will use the given {@code rabbitProperties}.
@@ -63,31 +65,31 @@ protected AbstractRabbitListenerContainerFactoryConfigurer(RabbitProperties rabb
6365
* converter should be used.
6466
* @param messageConverter the {@link MessageConverter}
6567
*/
66-
protected void setMessageConverter(MessageConverter messageConverter) {
68+
protected void setMessageConverter(@Nullable MessageConverter messageConverter) {
6769
this.messageConverter = messageConverter;
6870
}
6971

7072
/**
7173
* Set the {@link MessageRecoverer} to use or {@code null} to rely on the default.
7274
* @param messageRecoverer the {@link MessageRecoverer}
7375
*/
74-
protected void setMessageRecoverer(MessageRecoverer messageRecoverer) {
76+
protected void setMessageRecoverer(@Nullable MessageRecoverer messageRecoverer) {
7577
this.messageRecoverer = messageRecoverer;
7678
}
7779

7880
/**
7981
* Set the {@link RabbitRetryTemplateCustomizer} instances to use.
8082
* @param retryTemplateCustomizers the retry template customizers
8183
*/
82-
protected void setRetryTemplateCustomizers(List<RabbitRetryTemplateCustomizer> retryTemplateCustomizers) {
84+
protected void setRetryTemplateCustomizers(@Nullable List<RabbitRetryTemplateCustomizer> retryTemplateCustomizers) {
8385
this.retryTemplateCustomizers = retryTemplateCustomizers;
8486
}
8587

8688
/**
8789
* Set the task executor to use.
8890
* @param taskExecutor the task executor
8991
*/
90-
public void setTaskExecutor(Executor taskExecutor) {
92+
public void setTaskExecutor(@Nullable Executor taskExecutor) {
9193
this.taskExecutor = taskExecutor;
9294
}
9395

module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/PropertiesRabbitConnectionDetails.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.amqp.autoconfigure.RabbitProperties.Ssl;
2325
import org.springframework.boot.ssl.SslBundle;
2426
import org.springframework.boot.ssl.SslBundles;
@@ -36,9 +38,9 @@ class PropertiesRabbitConnectionDetails implements RabbitConnectionDetails {
3638

3739
private final RabbitProperties properties;
3840

39-
private final SslBundles sslBundles;
41+
private final @Nullable SslBundles sslBundles;
4042

41-
PropertiesRabbitConnectionDetails(RabbitProperties properties, SslBundles sslBundles) {
43+
PropertiesRabbitConnectionDetails(RabbitProperties properties, @Nullable SslBundles sslBundles) {
4244
this.properties = properties;
4345
this.sslBundles = sslBundles;
4446
}
@@ -49,12 +51,12 @@ public String getUsername() {
4951
}
5052

5153
@Override
52-
public String getPassword() {
54+
public @Nullable String getPassword() {
5355
return this.properties.determinePassword();
5456
}
5557

5658
@Override
57-
public String getVirtualHost() {
59+
public @Nullable String getVirtualHost() {
5860
return this.properties.determineVirtualHost();
5961
}
6062

@@ -71,7 +73,7 @@ public List<Address> getAddresses() {
7173
}
7274

7375
@Override
74-
public SslBundle getSslBundle() {
76+
public @Nullable SslBundle getSslBundle() {
7577
Ssl ssl = this.properties.getSsl();
7678
if (!ssl.determineEnabled()) {
7779
return null;

module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitConnectionDetails.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.List;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
2224
import org.springframework.boot.ssl.SslBundle;
2325
import org.springframework.util.Assert;
@@ -36,23 +38,23 @@ public interface RabbitConnectionDetails extends ConnectionDetails {
3638
* Login user to authenticate to the broker.
3739
* @return the login user to authenticate to the broker or {@code null}
3840
*/
39-
default String getUsername() {
41+
default @Nullable String getUsername() {
4042
return null;
4143
}
4244

4345
/**
4446
* Login to authenticate against the broker.
4547
* @return the login to authenticate against the broker or {@code null}
4648
*/
47-
default String getPassword() {
49+
default @Nullable String getPassword() {
4850
return null;
4951
}
5052

5153
/**
5254
* Virtual host to use when connecting to the broker.
5355
* @return the virtual host to use when connecting to the broker or {@code null}
5456
*/
55-
default String getVirtualHost() {
57+
default @Nullable String getVirtualHost() {
5658
return null;
5759
}
5860

@@ -78,7 +80,7 @@ default Address getFirstAddress() {
7880
* SSL bundle to use.
7981
* @return the SSL bundle to use
8082
*/
81-
default SslBundle getSslBundle() {
83+
default @Nullable SslBundle getSslBundle() {
8284
return null;
8385
}
8486

module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/autoconfigure/RabbitConnectionFactoryBeanConfigurer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.rabbitmq.client.impl.CredentialsProvider;
2222
import com.rabbitmq.client.impl.CredentialsRefreshService;
23+
import org.jspecify.annotations.Nullable;
2324

2425
import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
2526
import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails.Address;
@@ -53,9 +54,9 @@ public class RabbitConnectionFactoryBeanConfigurer {
5354

5455
private final RabbitConnectionDetails connectionDetails;
5556

56-
private CredentialsProvider credentialsProvider;
57+
private @Nullable CredentialsProvider credentialsProvider;
5758

58-
private CredentialsRefreshService credentialsRefreshService;
59+
private @Nullable CredentialsRefreshService credentialsRefreshService;
5960

6061
/**
6162
* Creates a new configurer that will use the given {@code resourceLoader} and
@@ -90,7 +91,7 @@ public RabbitConnectionFactoryBeanConfigurer(ResourceLoader resourceLoader, Rabb
9091
* @param sslBundles the SSL bundles
9192
*/
9293
public RabbitConnectionFactoryBeanConfigurer(ResourceLoader resourceLoader, RabbitProperties properties,
93-
RabbitConnectionDetails connectionDetails, SslBundles sslBundles) {
94+
RabbitConnectionDetails connectionDetails, @Nullable SslBundles sslBundles) {
9495
Assert.notNull(resourceLoader, "'resourceLoader' must not be null");
9596
Assert.notNull(properties, "'properties' must not be null");
9697
Assert.notNull(connectionDetails, "'connectionDetails' must not be null");
@@ -99,11 +100,11 @@ public RabbitConnectionFactoryBeanConfigurer(ResourceLoader resourceLoader, Rabb
99100
this.connectionDetails = connectionDetails;
100101
}
101102

102-
public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
103+
public void setCredentialsProvider(@Nullable CredentialsProvider credentialsProvider) {
103104
this.credentialsProvider = credentialsProvider;
104105
}
105106

106-
public void setCredentialsRefreshService(CredentialsRefreshService credentialsRefreshService) {
107+
public void setCredentialsRefreshService(@Nullable CredentialsRefreshService credentialsRefreshService) {
107108
this.credentialsRefreshService = credentialsRefreshService;
108109
}
109110

0 commit comments

Comments
 (0)