mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-29 21:59:02 +00:00
Add nullability annotations to module/spring-boot-mail
See gh-46587
This commit is contained in:
+22
-20
@@ -21,6 +21,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@@ -39,22 +41,22 @@ public class MailProperties {
|
||||
/**
|
||||
* SMTP server host. For instance, 'smtp.example.com'.
|
||||
*/
|
||||
private String host;
|
||||
private @Nullable String host;
|
||||
|
||||
/**
|
||||
* SMTP server port.
|
||||
*/
|
||||
private Integer port;
|
||||
private @Nullable Integer port;
|
||||
|
||||
/**
|
||||
* Login user of the SMTP server.
|
||||
*/
|
||||
private String username;
|
||||
private @Nullable String username;
|
||||
|
||||
/**
|
||||
* Login password of the SMTP server.
|
||||
*/
|
||||
private String password;
|
||||
private @Nullable String password;
|
||||
|
||||
/**
|
||||
* Protocol used by the SMTP server.
|
||||
@@ -74,42 +76,42 @@ public class MailProperties {
|
||||
/**
|
||||
* Session JNDI name. When set, takes precedence over other Session settings.
|
||||
*/
|
||||
private String jndiName;
|
||||
private @Nullable String jndiName;
|
||||
|
||||
/**
|
||||
* SSL configuration.
|
||||
*/
|
||||
private final Ssl ssl = new Ssl();
|
||||
|
||||
public String getHost() {
|
||||
public @Nullable String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
public void setHost(@Nullable String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
public @Nullable Integer getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
public void setPort(@Nullable Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -133,12 +135,12 @@ public class MailProperties {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setJndiName(String jndiName) {
|
||||
this.jndiName = jndiName;
|
||||
public @Nullable String getJndiName() {
|
||||
return this.jndiName;
|
||||
}
|
||||
|
||||
public String getJndiName() {
|
||||
return this.jndiName;
|
||||
public void setJndiName(@Nullable String jndiName) {
|
||||
this.jndiName = jndiName;
|
||||
}
|
||||
|
||||
public Ssl getSsl() {
|
||||
@@ -160,7 +162,7 @@ public class MailProperties {
|
||||
* Note that the STARTTLS command can use the corresponding SSLSocketFactory, even
|
||||
* if the 'mail.(protocol).ssl.enable' property is not set.
|
||||
*/
|
||||
private String bundle;
|
||||
private @Nullable String bundle;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
@@ -170,11 +172,11 @@ public class MailProperties {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -29,6 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jndi.JndiLocatorDelegate;
|
||||
import org.springframework.mail.MailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Auto-configure a {@link MailSender} based on a {@link Session} available on JNDI.
|
||||
@@ -60,6 +61,7 @@ class MailSenderJndiConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
Session session() {
|
||||
String jndiName = this.properties.getJndiName();
|
||||
Assert.state(jndiName != null, "'jndiName' must not be null");
|
||||
try {
|
||||
return JndiLocatorDelegate.createDefaultResourceRefLocator().lookup(jndiName, Session.class);
|
||||
}
|
||||
|
||||
+6
-1
@@ -19,6 +19,8 @@ package org.springframework.boot.mail.autoconfigure;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -30,6 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mail.MailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -51,7 +54,8 @@ class MailSenderPropertiesConfiguration {
|
||||
return sender;
|
||||
}
|
||||
|
||||
private void applyProperties(MailProperties properties, JavaMailSenderImpl sender, SslBundles sslBundles) {
|
||||
private void applyProperties(MailProperties properties, JavaMailSenderImpl sender,
|
||||
@Nullable SslBundles sslBundles) {
|
||||
sender.setHost(properties.getHost());
|
||||
if (properties.getPort() != null) {
|
||||
sender.setPort(properties.getPort());
|
||||
@@ -70,6 +74,7 @@ class MailSenderPropertiesConfiguration {
|
||||
javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true");
|
||||
}
|
||||
if (ssl.getBundle() != null) {
|
||||
Assert.state(sslBundles != null, "'sslBundles' must not be null");
|
||||
SslBundle sslBundle = sslBundles.getBundle(ssl.getBundle());
|
||||
javaMailProperties.put("mail." + protocol + ".ssl.socketFactory",
|
||||
sslBundle.createSslContext().getSocketFactory());
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Auto-configuration for email support.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.mail.autoconfigure;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Health integration for JavaMail.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.mail.health;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
Reference in New Issue
Block a user