From d78d803525a781e20592191c28c0b272e0268686 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 5 Aug 2025 13:31:27 +0200 Subject: [PATCH] Add nullability annotations to module/spring-boot-sendgrid See gh-46587 --- .../SendGridAutoConfiguration.java | 3 +- .../autoconfigure/SendGridProperties.java | 30 +++++++++---------- .../sendgrid/autoconfigure/package-info.java | 3 ++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridAutoConfiguration.java b/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridAutoConfiguration.java index 8158c6dba74..acb9cce2a80 100644 --- a/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridAutoConfiguration.java +++ b/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridAutoConfiguration.java @@ -47,7 +47,8 @@ public final class SendGridAutoConfiguration { @Bean @ConditionalOnMissingBean(SendGridAPI.class) SendGrid sendGrid(SendGridProperties properties) { - if (properties.isProxyConfigured()) { + if (properties.getProxy() != null && properties.getProxy().getHost() != null + && properties.getProxy().getPort() != null) { HttpHost proxy = new HttpHost(properties.getProxy().getHost(), properties.getProxy().getPort()); return new SendGrid(properties.getApiKey(), new Client(HttpClientBuilder.create().setProxy(proxy).build())); } diff --git a/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridProperties.java b/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridProperties.java index 6d79cc13245..173ef8ee04d 100644 --- a/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridProperties.java +++ b/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/SendGridProperties.java @@ -16,6 +16,8 @@ package org.springframework.boot.sendgrid.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -31,58 +33,54 @@ public class SendGridProperties { /** * SendGrid API key. */ - private String apiKey; + private @Nullable String apiKey; /** * Proxy configuration. */ - private Proxy proxy; + private @Nullable Proxy proxy; - public String getApiKey() { + public @Nullable String getApiKey() { return this.apiKey; } - public void setApiKey(String apiKey) { + public void setApiKey(@Nullable String apiKey) { this.apiKey = apiKey; } - public Proxy getProxy() { + public @Nullable Proxy getProxy() { return this.proxy; } - public void setProxy(Proxy proxy) { + public void setProxy(@Nullable Proxy proxy) { this.proxy = proxy; } - public boolean isProxyConfigured() { - return this.proxy != null && this.proxy.getHost() != null && this.proxy.getPort() != null; - } - public static class Proxy { /** * SendGrid proxy host. */ - private String host; + private @Nullable String host; /** * SendGrid proxy port. */ - private Integer port; + private @Nullable Integer port; - 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; } diff --git a/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/package-info.java b/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/package-info.java index 35239ab01d1..772aaab1269 100644 --- a/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/package-info.java +++ b/module/spring-boot-sendgrid/src/main/java/org/springframework/boot/sendgrid/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for SendGrid. */ +@NullMarked package org.springframework.boot.sendgrid.autoconfigure; + +import org.jspecify.annotations.NullMarked;