Skip to content

Commit e30cad4

Browse files
committed
Add nullability annotations to module/spring-boot-web-server
See gh-46587
1 parent 2ce974c commit e30cad4

File tree

51 files changed

+394
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+394
-258
lines changed

documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/configure/MyTomcatWebServerCustomizer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package org.springframework.boot.docs.howto.webserver.configure
1818

19-
import org.springframework.boot.web.server.WebServerFactoryCustomizer
2019
import org.springframework.boot.tomcat.servlet.TomcatServletWebServerFactory
20+
import org.springframework.boot.web.server.WebServerFactoryCustomizer
2121
import org.springframework.stereotype.Component
2222

2323
@Component
24-
class MyTomcatWebServerCustomizer : WebServerFactoryCustomizer<TomcatServletWebServerFactory?> {
24+
class MyTomcatWebServerCustomizer : WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
2525

26-
override fun customize(factory: TomcatServletWebServerFactory?) {
26+
override fun customize(factory: TomcatServletWebServerFactory) {
2727
// customize the factory here
2828
}
2929

module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Set;
2727
import java.util.stream.Collectors;
2828

29+
import org.jspecify.annotations.Nullable;
30+
2931
import org.springframework.boot.ssl.SslBundle;
3032
import org.springframework.boot.ssl.SslBundles;
3133
import org.springframework.boot.web.error.ErrorPage;
@@ -49,19 +51,19 @@ public abstract class AbstractConfigurableWebServerFactory implements Configurab
4951

5052
private int port = 8080;
5153

52-
private InetAddress address;
54+
private @Nullable InetAddress address;
5355

5456
private Set<ErrorPage> errorPages = new LinkedHashSet<>();
5557

56-
private Ssl ssl;
58+
private @Nullable Ssl ssl;
5759

58-
private SslBundles sslBundles;
60+
private @Nullable SslBundles sslBundles;
5961

60-
private Http2 http2;
62+
private @Nullable Http2 http2;
6163

62-
private Compression compression;
64+
private @Nullable Compression compression;
6365

64-
private String serverHeader;
66+
private @Nullable String serverHeader;
6567

6668
private Shutdown shutdown = Shutdown.IMMEDIATE;
6769

@@ -97,12 +99,12 @@ public void setPort(int port) {
9799
* Return the address that the web server binds to.
98100
* @return the address
99101
*/
100-
public InetAddress getAddress() {
102+
public @Nullable InetAddress getAddress() {
101103
return this.address;
102104
}
103105

104106
@Override
105-
public void setAddress(InetAddress address) {
107+
public void setAddress(@Nullable InetAddress address) {
106108
this.address = address;
107109
}
108110

@@ -127,12 +129,12 @@ public void addErrorPages(ErrorPage... errorPages) {
127129
this.errorPages.addAll(Arrays.asList(errorPages));
128130
}
129131

130-
public Ssl getSsl() {
132+
public @Nullable Ssl getSsl() {
131133
return this.ssl;
132134
}
133135

134136
@Override
135-
public void setSsl(Ssl ssl) {
137+
public void setSsl(@Nullable Ssl ssl) {
136138
this.ssl = ssl;
137139
}
138140

@@ -141,39 +143,39 @@ public void setSsl(Ssl ssl) {
141143
* @return the {@link SslBundles} or {@code null}
142144
* @since 3.2.0
143145
*/
144-
public SslBundles getSslBundles() {
146+
public @Nullable SslBundles getSslBundles() {
145147
return this.sslBundles;
146148
}
147149

148150
@Override
149-
public void setSslBundles(SslBundles sslBundles) {
151+
public void setSslBundles(@Nullable SslBundles sslBundles) {
150152
this.sslBundles = sslBundles;
151153
}
152154

153-
public Http2 getHttp2() {
155+
public @Nullable Http2 getHttp2() {
154156
return this.http2;
155157
}
156158

157159
@Override
158-
public void setHttp2(Http2 http2) {
160+
public void setHttp2(@Nullable Http2 http2) {
159161
this.http2 = http2;
160162
}
161163

162-
public Compression getCompression() {
164+
public @Nullable Compression getCompression() {
163165
return this.compression;
164166
}
165167

166168
@Override
167-
public void setCompression(Compression compression) {
169+
public void setCompression(@Nullable Compression compression) {
168170
this.compression = compression;
169171
}
170172

171-
public String getServerHeader() {
173+
public @Nullable String getServerHeader() {
172174
return this.serverHeader;
173175
}
174176

175177
@Override
176-
public void setServerHeader(String serverHeader) {
178+
public void setServerHeader(@Nullable String serverHeader) {
177179
this.serverHeader = serverHeader;
178180
}
179181

@@ -200,10 +202,13 @@ protected final SslBundle getSslBundle() {
200202
}
201203

202204
protected final Map<String, SslBundle> getServerNameSslBundles() {
205+
Assert.state(this.ssl != null, "'ssl' must not be null");
203206
return this.ssl.getServerNameBundles()
204207
.stream()
205-
.collect(Collectors.toMap(ServerNameSslBundle::serverName,
206-
(serverNameSslBundle) -> this.sslBundles.getBundle(serverNameSslBundle.bundle())));
208+
.collect(Collectors.toMap(ServerNameSslBundle::serverName, (serverNameSslBundle) -> {
209+
Assert.state(this.sslBundles != null, "'sslBundles' must not be null");
210+
return this.sslBundles.getBundle(serverNameSslBundle.bundle());
211+
}));
207212
}
208213

209214
/**

module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/Compression.java

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

1717
package org.springframework.boot.web.server;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.context.properties.ConfigurationPropertiesSource;
2022
import org.springframework.util.unit.DataSize;
2123

@@ -44,7 +46,7 @@ public class Compression {
4446
/**
4547
* Comma-separated list of user agents for which responses should not be compressed.
4648
*/
47-
private String[] excludedUserAgents = null;
49+
private String @Nullable [] excludedUserAgents;
4850

4951
/**
5052
* Minimum "Content-Length" value that is required for compression to be performed.
@@ -75,11 +77,11 @@ public void setMimeTypes(String[] mimeTypes) {
7577
this.mimeTypes = mimeTypes;
7678
}
7779

78-
public String[] getExcludedUserAgents() {
80+
public String @Nullable [] getExcludedUserAgents() {
7981
return this.excludedUserAgents;
8082
}
8183

82-
public void setExcludedUserAgents(String[] excludedUserAgents) {
84+
public void setExcludedUserAgents(String @Nullable [] excludedUserAgents) {
8385
this.excludedUserAgents = excludedUserAgents;
8486
}
8587

module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.net.InetAddress;
2020
import java.util.Set;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.ssl.SslBundles;
2325
import org.springframework.boot.web.error.ErrorPage;
2426
import org.springframework.boot.web.error.ErrorPageRegistry;
@@ -46,7 +48,7 @@ public interface ConfigurableWebServerFactory extends WebServerFactory, ErrorPag
4648
* Sets the specific network address that the server should bind to.
4749
* @param address the address to set (defaults to {@code null})
4850
*/
49-
void setAddress(InetAddress address);
51+
void setAddress(@Nullable InetAddress address);
5052

5153
/**
5254
* Sets the error pages that will be used when handling exceptions.
@@ -58,33 +60,33 @@ public interface ConfigurableWebServerFactory extends WebServerFactory, ErrorPag
5860
* Sets the SSL configuration that will be applied to the server's default connector.
5961
* @param ssl the SSL configuration
6062
*/
61-
void setSsl(Ssl ssl);
63+
void setSsl(@Nullable Ssl ssl);
6264

6365
/**
6466
* Sets the SSL bundles that can be used to configure SSL connections.
6567
* @param sslBundles the SSL bundles
6668
* @since 3.1.0
6769
*/
68-
void setSslBundles(SslBundles sslBundles);
70+
void setSslBundles(@Nullable SslBundles sslBundles);
6971

7072
/**
7173
* Sets the HTTP/2 configuration that will be applied to the server.
7274
* @param http2 the HTTP/2 configuration
7375
*/
74-
void setHttp2(Http2 http2);
76+
void setHttp2(@Nullable Http2 http2);
7577

7678
/**
7779
* Sets the compression configuration that will be applied to the server's default
7880
* connector.
7981
* @param compression the compression configuration
8082
*/
81-
void setCompression(Compression compression);
83+
void setCompression(@Nullable Compression compression);
8284

8385
/**
8486
* Sets the server header value.
8587
* @param serverHeader the server header value
8688
*/
87-
void setServerHeader(String serverHeader);
89+
void setServerHeader(@Nullable String serverHeader);
8890

8991
/**
9092
* Sets the shutdown configuration that will be applied to the server.

module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/Cookie.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.time.Duration;
2020
import java.time.temporal.ChronoUnit;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.context.properties.ConfigurationPropertiesSource;
2325
import org.springframework.boot.convert.DurationUnit;
2426

@@ -37,32 +39,32 @@ public class Cookie {
3739
/**
3840
* Name for the cookie.
3941
*/
40-
private String name;
42+
private @Nullable String name;
4143

4244
/**
4345
* Domain for the cookie.
4446
*/
45-
private String domain;
47+
private @Nullable String domain;
4648

4749
/**
4850
* Path of the cookie.
4951
*/
50-
private String path;
52+
private @Nullable String path;
5153

5254
/**
5355
* Whether to use "HttpOnly" cookies for the cookie.
5456
*/
55-
private Boolean httpOnly;
57+
private @Nullable Boolean httpOnly;
5658

5759
/**
5860
* Whether to always mark the cookie as secure.
5961
*/
60-
private Boolean secure;
62+
private @Nullable Boolean secure;
6163

6264
/**
6365
* Whether the generated cookie carries the Partitioned attribute.
6466
*/
65-
private Boolean partitioned;
67+
private @Nullable Boolean partitioned;
6668

6769
/**
6870
* Maximum age of the cookie. If a duration suffix is not specified, seconds will be
@@ -71,74 +73,74 @@ public class Cookie {
7173
* means no "Max-Age".
7274
*/
7375
@DurationUnit(ChronoUnit.SECONDS)
74-
private Duration maxAge;
76+
private @Nullable Duration maxAge;
7577

7678
/**
7779
* SameSite setting for the cookie.
7880
*/
79-
private SameSite sameSite;
81+
private @Nullable SameSite sameSite;
8082

81-
public String getName() {
83+
public @Nullable String getName() {
8284
return this.name;
8385
}
8486

85-
public void setName(String name) {
87+
public void setName(@Nullable String name) {
8688
this.name = name;
8789
}
8890

89-
public String getDomain() {
91+
public @Nullable String getDomain() {
9092
return this.domain;
9193
}
9294

93-
public void setDomain(String domain) {
95+
public void setDomain(@Nullable String domain) {
9496
this.domain = domain;
9597
}
9698

97-
public String getPath() {
99+
public @Nullable String getPath() {
98100
return this.path;
99101
}
100102

101-
public void setPath(String path) {
103+
public void setPath(@Nullable String path) {
102104
this.path = path;
103105
}
104106

105-
public Boolean getHttpOnly() {
107+
public @Nullable Boolean getHttpOnly() {
106108
return this.httpOnly;
107109
}
108110

109-
public void setHttpOnly(Boolean httpOnly) {
111+
public void setHttpOnly(@Nullable Boolean httpOnly) {
110112
this.httpOnly = httpOnly;
111113
}
112114

113-
public Boolean getSecure() {
115+
public @Nullable Boolean getSecure() {
114116
return this.secure;
115117
}
116118

117-
public void setSecure(Boolean secure) {
119+
public void setSecure(@Nullable Boolean secure) {
118120
this.secure = secure;
119121
}
120122

121-
public Duration getMaxAge() {
123+
public @Nullable Duration getMaxAge() {
122124
return this.maxAge;
123125
}
124126

125-
public void setMaxAge(Duration maxAge) {
127+
public void setMaxAge(@Nullable Duration maxAge) {
126128
this.maxAge = maxAge;
127129
}
128130

129-
public SameSite getSameSite() {
131+
public @Nullable SameSite getSameSite() {
130132
return this.sameSite;
131133
}
132134

133-
public void setSameSite(SameSite sameSite) {
135+
public void setSameSite(@Nullable SameSite sameSite) {
134136
this.sameSite = sameSite;
135137
}
136138

137-
public Boolean getPartitioned() {
139+
public @Nullable Boolean getPartitioned() {
138140
return this.partitioned;
139141
}
140142

141-
public void setPartitioned(Boolean partitioned) {
143+
public void setPartitioned(@Nullable Boolean partitioned) {
142144
this.partitioned = partitioned;
143145
}
144146

@@ -170,13 +172,13 @@ public enum SameSite {
170172
*/
171173
STRICT("Strict");
172174

173-
private final String attributeValue;
175+
private @Nullable final String attributeValue;
174176

175-
SameSite(String attributeValue) {
177+
SameSite(@Nullable String attributeValue) {
176178
this.attributeValue = attributeValue;
177179
}
178180

179-
public String attributeValue() {
181+
public @Nullable String attributeValue() {
180182
return this.attributeValue;
181183
}
182184

0 commit comments

Comments
 (0)