Skip to content

Commit 1c13bba

Browse files
committed
Add nullability annotations to module/spring-boot-mail
See gh-46587
1 parent 567c602 commit 1c13bba

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailProperties.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.context.properties.ConfigurationProperties;
2527

2628
/**
@@ -39,22 +41,22 @@ public class MailProperties {
3941
/**
4042
* SMTP server host. For instance, 'smtp.example.com'.
4143
*/
42-
private String host;
44+
private @Nullable String host;
4345

4446
/**
4547
* SMTP server port.
4648
*/
47-
private Integer port;
49+
private @Nullable Integer port;
4850

4951
/**
5052
* Login user of the SMTP server.
5153
*/
52-
private String username;
54+
private @Nullable String username;
5355

5456
/**
5557
* Login password of the SMTP server.
5658
*/
57-
private String password;
59+
private @Nullable String password;
5860

5961
/**
6062
* Protocol used by the SMTP server.
@@ -74,42 +76,42 @@ public class MailProperties {
7476
/**
7577
* Session JNDI name. When set, takes precedence over other Session settings.
7678
*/
77-
private String jndiName;
79+
private @Nullable String jndiName;
7880

7981
/**
8082
* SSL configuration.
8183
*/
8284
private final Ssl ssl = new Ssl();
8385

84-
public String getHost() {
86+
public @Nullable String getHost() {
8587
return this.host;
8688
}
8789

88-
public void setHost(String host) {
90+
public void setHost(@Nullable String host) {
8991
this.host = host;
9092
}
9193

92-
public Integer getPort() {
94+
public @Nullable Integer getPort() {
9395
return this.port;
9496
}
9597

96-
public void setPort(Integer port) {
98+
public void setPort(@Nullable Integer port) {
9799
this.port = port;
98100
}
99101

100-
public String getUsername() {
102+
public @Nullable String getUsername() {
101103
return this.username;
102104
}
103105

104-
public void setUsername(String username) {
106+
public void setUsername(@Nullable String username) {
105107
this.username = username;
106108
}
107109

108-
public String getPassword() {
110+
public @Nullable String getPassword() {
109111
return this.password;
110112
}
111113

112-
public void setPassword(String password) {
114+
public void setPassword(@Nullable String password) {
113115
this.password = password;
114116
}
115117

@@ -133,12 +135,12 @@ public Map<String, String> getProperties() {
133135
return this.properties;
134136
}
135137

136-
public void setJndiName(String jndiName) {
137-
this.jndiName = jndiName;
138+
public @Nullable String getJndiName() {
139+
return this.jndiName;
138140
}
139141

140-
public String getJndiName() {
141-
return this.jndiName;
142+
public void setJndiName(@Nullable String jndiName) {
143+
this.jndiName = jndiName;
142144
}
143145

144146
public Ssl getSsl() {
@@ -160,7 +162,7 @@ public static class Ssl {
160162
* Note that the STARTTLS command can use the corresponding SSLSocketFactory, even
161163
* if the 'mail.(protocol).ssl.enable' property is not set.
162164
*/
163-
private String bundle;
165+
private @Nullable String bundle;
164166

165167
public boolean isEnabled() {
166168
return this.enabled;
@@ -170,11 +172,11 @@ public void setEnabled(boolean enabled) {
170172
this.enabled = enabled;
171173
}
172174

173-
public String getBundle() {
175+
public @Nullable String getBundle() {
174176
return this.bundle;
175177
}
176178

177-
public void setBundle(String bundle) {
179+
public void setBundle(@Nullable String bundle) {
178180
this.bundle = bundle;
179181
}
180182

module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailSenderJndiConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.jndi.JndiLocatorDelegate;
3030
import org.springframework.mail.MailSender;
3131
import org.springframework.mail.javamail.JavaMailSenderImpl;
32+
import org.springframework.util.Assert;
3233

3334
/**
3435
* Auto-configure a {@link MailSender} based on a {@link Session} available on JNDI.
@@ -60,6 +61,7 @@ JavaMailSenderImpl mailSender(Session session) {
6061
@ConditionalOnMissingBean
6162
Session session() {
6263
String jndiName = this.properties.getJndiName();
64+
Assert.state(jndiName != null, "'jndiName' must not be null");
6365
try {
6466
return JndiLocatorDelegate.createDefaultResourceRefLocator().lookup(jndiName, Session.class);
6567
}

module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailSenderPropertiesConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Map;
2020
import java.util.Properties;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.beans.factory.ObjectProvider;
2325
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2426
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -30,6 +32,7 @@
3032
import org.springframework.mail.MailSender;
3133
import org.springframework.mail.javamail.JavaMailSender;
3234
import org.springframework.mail.javamail.JavaMailSenderImpl;
35+
import org.springframework.util.Assert;
3336
import org.springframework.util.StringUtils;
3437

3538
/**
@@ -51,7 +54,8 @@ JavaMailSenderImpl mailSender(MailProperties properties, ObjectProvider<SslBundl
5154
return sender;
5255
}
5356

54-
private void applyProperties(MailProperties properties, JavaMailSenderImpl sender, SslBundles sslBundles) {
57+
private void applyProperties(MailProperties properties, JavaMailSenderImpl sender,
58+
@Nullable SslBundles sslBundles) {
5559
sender.setHost(properties.getHost());
5660
if (properties.getPort() != null) {
5761
sender.setPort(properties.getPort());
@@ -70,6 +74,7 @@ private void applyProperties(MailProperties properties, JavaMailSenderImpl sende
7074
javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true");
7175
}
7276
if (ssl.getBundle() != null) {
77+
Assert.state(sslBundles != null, "'sslBundles' must not be null");
7378
SslBundle sslBundle = sslBundles.getBundle(ssl.getBundle());
7479
javaMailProperties.put("mail." + protocol + ".ssl.socketFactory",
7580
sslBundle.createSslContext().getSocketFactory());

module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for email support.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.mail.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-mail/src/main/java/org/springframework/boot/mail/health/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Health integration for JavaMail.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.mail.health;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)