Skip to content

Commit 526b9d0

Browse files
committed
Add nullability annotations to module/spring-boot-reactor-netty
See gh-46587
1 parent 87c5d57 commit 526b9d0

File tree

12 files changed

+67
-53
lines changed

12 files changed

+67
-53
lines changed

module/spring-boot-reactor-netty/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ dependencies {
2929
api("io.projectreactor.netty:reactor-netty-http")
3030
api("org.springframework:spring-web")
3131

32+
compileOnly("com.google.code.findbugs:jsr305")
33+
3234
implementation(project(":module:spring-boot-netty"))
3335

3436
optional(project(":core:spring-boot-autoconfigure"))

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/CompressionCustomizer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import io.netty.handler.codec.http.HttpHeaderNames;
2424
import io.netty.handler.codec.http.HttpHeaders;
25+
import org.jspecify.annotations.Nullable;
2526
import reactor.netty.http.server.HttpServer;
2627
import reactor.netty.http.server.HttpServerRequest;
2728
import reactor.netty.http.server.HttpServerResponse;
@@ -82,7 +83,7 @@ private CompressionPredicate getMimeTypesPredicate(String[] mimeTypeValues) {
8283
};
8384
}
8485

85-
private CompressionPredicate getExcludedUserAgentsPredicate(String[] excludedUserAgents) {
86+
private CompressionPredicate getExcludedUserAgentsPredicate(String @Nullable [] excludedUserAgents) {
8687
if (ObjectUtils.isEmpty(excludedUserAgents)) {
8788
return ALWAYS_COMPRESS;
8889
}

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/GracefulShutdown.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
import org.jspecify.annotations.Nullable;
2425
import reactor.netty.DisposableServer;
2526

2627
import org.springframework.boot.web.server.GracefulShutdownCallback;
@@ -35,13 +36,13 @@ final class GracefulShutdown {
3536

3637
private static final Log logger = LogFactory.getLog(GracefulShutdown.class);
3738

38-
private final Supplier<DisposableServer> disposableServer;
39+
private final Supplier<@Nullable DisposableServer> disposableServer;
3940

40-
private volatile Thread shutdownThread;
41+
private volatile @Nullable Thread shutdownThread;
4142

4243
private volatile boolean shuttingDown;
4344

44-
GracefulShutdown(Supplier<DisposableServer> disposableServer) {
45+
GracefulShutdown(Supplier<@Nullable DisposableServer> disposableServer) {
4546
this.disposableServer = disposableServer;
4647
}
4748

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/NettyReactiveWebServerFactory.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import java.util.List;
2626
import java.util.Set;
2727

28+
import org.jspecify.annotations.Nullable;
2829
import reactor.netty.http.HttpProtocol;
2930
import reactor.netty.http.server.HttpServer;
3031

32+
import org.springframework.boot.ssl.SslBundles;
3133
import org.springframework.boot.web.server.Shutdown;
3234
import org.springframework.boot.web.server.Ssl;
3335
import org.springframework.boot.web.server.WebServer;
@@ -53,13 +55,11 @@ public class NettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
5355

5456
private final List<NettyRouteProvider> routeProviders = new ArrayList<>();
5557

56-
private Duration lifecycleTimeout;
58+
private @Nullable Duration lifecycleTimeout;
5759

5860
private boolean useForwardHeaders;
5961

60-
private ReactorResourceFactory resourceFactory;
61-
62-
private Shutdown shutdown;
62+
private @Nullable ReactorResourceFactory resourceFactory;
6363

6464
public NettyReactiveWebServerFactory() {
6565
}
@@ -79,7 +79,7 @@ public WebServer getWebServer(HttpHandler httpHandler) {
7979
}
8080

8181
NettyWebServer createNettyWebServer(HttpServer httpServer, ReactorHttpHandlerAdapter handlerAdapter,
82-
Duration lifecycleTimeout, Shutdown shutdown) {
82+
@Nullable Duration lifecycleTimeout, Shutdown shutdown) {
8383
return new NettyWebServer(httpServer, handlerAdapter, lifecycleTimeout, shutdown, this.resourceFactory);
8484
}
8585

@@ -127,7 +127,7 @@ public void addRouteProviders(NettyRouteProvider... routeProviders) {
127127
* server.
128128
* @param lifecycleTimeout the lifecycle timeout
129129
*/
130-
public void setLifecycleTimeout(Duration lifecycleTimeout) {
130+
public void setLifecycleTimeout(@Nullable Duration lifecycleTimeout) {
131131
this.lifecycleTimeout = lifecycleTimeout;
132132
}
133133

@@ -145,24 +145,15 @@ public void setUseForwardHeaders(boolean useForwardHeaders) {
145145
* @param resourceFactory the server resources
146146
* @since 4.0.0
147147
*/
148-
public void setResourceFactory(ReactorResourceFactory resourceFactory) {
148+
public void setResourceFactory(@Nullable ReactorResourceFactory resourceFactory) {
149149
this.resourceFactory = resourceFactory;
150150
}
151151

152-
@Override
153-
public void setShutdown(Shutdown shutdown) {
154-
this.shutdown = shutdown;
155-
}
156-
157-
@Override
158-
public Shutdown getShutdown() {
159-
return this.shutdown;
160-
}
161-
162152
private HttpServer createHttpServer() {
163153
HttpServer server = HttpServer.create().bindAddress(this::getListenAddress);
164-
if (Ssl.isEnabled(getSsl())) {
165-
server = customizeSslConfiguration(server);
154+
Ssl ssl = getSsl();
155+
if (Ssl.isEnabled(ssl)) {
156+
server = customizeSslConfiguration(server, ssl);
166157
}
167158
if (getCompression() != null && getCompression().getEnabled()) {
168159
CompressionCustomizer compressionCustomizer = new CompressionCustomizer(getCompression());
@@ -172,19 +163,22 @@ private HttpServer createHttpServer() {
172163
return applyCustomizers(server);
173164
}
174165

175-
private HttpServer customizeSslConfiguration(HttpServer httpServer) {
176-
SslServerCustomizer customizer = new SslServerCustomizer(getHttp2(), getSsl().getClientAuth(), getSslBundle(),
166+
private HttpServer customizeSslConfiguration(HttpServer httpServer, Ssl ssl) {
167+
SslServerCustomizer customizer = new SslServerCustomizer(getHttp2(), ssl.getClientAuth(), getSslBundle(),
177168
getServerNameSslBundles());
178-
addBundleUpdateHandler(null, getSsl().getBundle(), customizer);
179-
getSsl().getServerNameBundles()
169+
addBundleUpdateHandler(null, ssl.getBundle(), customizer);
170+
ssl.getServerNameBundles()
180171
.forEach((serverNameSslBundle) -> addBundleUpdateHandler(serverNameSslBundle.serverName(),
181172
serverNameSslBundle.bundle(), customizer));
182173
return customizer.apply(httpServer);
183174
}
184175

185-
private void addBundleUpdateHandler(String serverName, String bundleName, SslServerCustomizer customizer) {
176+
private void addBundleUpdateHandler(@Nullable String serverName, @Nullable String bundleName,
177+
SslServerCustomizer customizer) {
186178
if (StringUtils.hasText(bundleName)) {
187-
getSslBundles().addBundleUpdateHandler(bundleName,
179+
SslBundles sslBundles = getSslBundles();
180+
Assert.state(sslBundles != null, "'sslBundles' must not be null");
181+
sslBundles.addBundleUpdateHandler(bundleName,
188182
(sslBundle) -> customizer.updateSslBundle(serverName, sslBundle));
189183
}
190184
}

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/NettyWebServer.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.netty.util.concurrent.DefaultEventExecutor;
2929
import org.apache.commons.logging.Log;
3030
import org.apache.commons.logging.LogFactory;
31+
import org.jspecify.annotations.Nullable;
3132
import org.reactivestreams.Publisher;
3233
import reactor.netty.ChannelBindException;
3334
import reactor.netty.DisposableServer;
@@ -72,15 +73,15 @@ public class NettyWebServer implements WebServer {
7273

7374
private final BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler;
7475

75-
private final Duration lifecycleTimeout;
76+
private final @Nullable Duration lifecycleTimeout;
7677

77-
private final GracefulShutdown gracefulShutdown;
78+
private final @Nullable GracefulShutdown gracefulShutdown;
7879

79-
private final ReactorResourceFactory resourceFactory;
80+
private final @Nullable ReactorResourceFactory resourceFactory;
8081

8182
private List<NettyRouteProvider> routeProviders = Collections.emptyList();
8283

83-
private volatile DisposableServer disposableServer;
84+
private volatile @Nullable DisposableServer disposableServer;
8485

8586
/**
8687
* Creates a new {@code NettyWebServer} instance.
@@ -92,8 +93,9 @@ public class NettyWebServer implements WebServer {
9293
* resources}, may be {@code null}
9394
* @since 4.0.0
9495
*/
95-
public NettyWebServer(HttpServer httpServer, ReactorHttpHandlerAdapter handlerAdapter, Duration lifecycleTimeout,
96-
Shutdown shutdown, ReactorResourceFactory resourceFactory) {
96+
public NettyWebServer(HttpServer httpServer, ReactorHttpHandlerAdapter handlerAdapter,
97+
@Nullable Duration lifecycleTimeout, @Nullable Shutdown shutdown,
98+
@Nullable ReactorResourceFactory resourceFactory) {
9799
Assert.notNull(httpServer, "'httpServer' must not be null");
98100
Assert.notNull(handlerAdapter, "'handlerAdapter' must not be null");
99101
this.lifecycleTimeout = lifecycleTimeout;
@@ -138,6 +140,7 @@ private String getStartedOnMessage(DisposableServer server) {
138140
}
139141

140142
protected String getStartedLogMessage() {
143+
Assert.state(this.disposableServer != null, "'disposableServer' must not be null");
141144
return getStartedOnMessage(this.disposableServer);
142145
}
143146

@@ -171,7 +174,7 @@ DisposableServer startHttpServer() {
171174
return server.bindNow();
172175
}
173176

174-
private boolean isPermissionDenied(Throwable bindExceptionCause) {
177+
private boolean isPermissionDenied(@Nullable Throwable bindExceptionCause) {
175178
try {
176179
if (bindExceptionCause instanceof NativeIoException nativeException) {
177180
return nativeException.expectedErr() == ERROR_NO_EACCES;

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/SslServerCustomizer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.netty.handler.ssl.ClientAuth;
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
25+
import org.jspecify.annotations.Nullable;
2526
import reactor.netty.http.Http11SslContextSpec;
2627
import reactor.netty.http.Http2SslContextSpec;
2728
import reactor.netty.http.server.HttpServer;
@@ -52,15 +53,15 @@ public class SslServerCustomizer implements NettyServerCustomizer {
5253

5354
private static final Log logger = LogFactory.getLog(SslServerCustomizer.class);
5455

55-
private final Http2 http2;
56+
private final @Nullable Http2 http2;
5657

5758
private final ClientAuth clientAuth;
5859

5960
private volatile SslProvider sslProvider;
6061

6162
private final Map<String, SslProvider> serverNameSslProviders;
6263

63-
public SslServerCustomizer(Http2 http2, Ssl.ClientAuth clientAuth, SslBundle sslBundle,
64+
public SslServerCustomizer(@Nullable Http2 http2, Ssl.@Nullable ClientAuth clientAuth, SslBundle sslBundle,
6465
Map<String, SslBundle> serverNameSslBundles) {
6566
this.http2 = http2;
6667
this.clientAuth = Ssl.ClientAuth.map(clientAuth, ClientAuth.NONE, ClientAuth.OPTIONAL, ClientAuth.REQUIRE);
@@ -82,7 +83,7 @@ private void applySecurity(SslContextSpec spec) {
8283
});
8384
}
8485

85-
void updateSslBundle(String serverName, SslBundle sslBundle) {
86+
void updateSslBundle(@Nullable String serverName, SslBundle sslBundle) {
8687
logger.debug("SSL Bundle has been updated, reloading SSL configuration");
8788
if (serverName == null) {
8889
this.sslProvider = createSslProvider(sslBundle);

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/autoconfigure/NettyReactiveWebServerFactoryCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void customize(NettyReactiveWebServerFactory factory) {
6666
map.from(this.nettyProperties::getIdleTimeout).to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
6767
map.from(this.nettyProperties::getMaxKeepAliveRequests)
6868
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
69-
if (this.serverProperties.getHttp2() != null && this.serverProperties.getHttp2().isEnabled()) {
69+
if (this.serverProperties.getHttp2().isEnabled()) {
7070
map.from(this.serverProperties.getMaxHttpRequestHeaderSize())
7171
.to((size) -> customizeHttp2MaxHeaderSize(factory, size.toBytes()));
7272
}

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/autoconfigure/NettyServerProperties.java

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

1919
import java.time.Duration;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.context.properties.ConfigurationProperties;
2224
import org.springframework.util.unit.DataSize;
2325

@@ -55,7 +57,7 @@ public class NettyServerProperties {
5557
/**
5658
* Connection timeout of the Netty channel.
5759
*/
58-
private Duration connectionTimeout;
60+
private @Nullable Duration connectionTimeout;
5961

6062
/**
6163
* Maximum content length of an H2C upgrade request.
@@ -76,7 +78,7 @@ public class NettyServerProperties {
7678
* Maximum number of requests that can be made per connection. By default, a
7779
* connection serves unlimited number of requests.
7880
*/
79-
private Integer maxKeepAliveRequests;
81+
private @Nullable Integer maxKeepAliveRequests;
8082

8183
/**
8284
* Whether to validate headers when decoding requests.
@@ -86,13 +88,13 @@ public class NettyServerProperties {
8688
/**
8789
* Idle timeout of the Netty channel. When not specified, an infinite timeout is used.
8890
*/
89-
private Duration idleTimeout;
91+
private @Nullable Duration idleTimeout;
9092

91-
public Duration getConnectionTimeout() {
93+
public @Nullable Duration getConnectionTimeout() {
9294
return this.connectionTimeout;
9395
}
9496

95-
public void setConnectionTimeout(Duration connectionTimeout) {
97+
public void setConnectionTimeout(@Nullable Duration connectionTimeout) {
9698
this.connectionTimeout = connectionTimeout;
9799
}
98100

@@ -120,11 +122,11 @@ public void setMaxInitialLineLength(DataSize maxInitialLineLength) {
120122
this.maxInitialLineLength = maxInitialLineLength;
121123
}
122124

123-
public Integer getMaxKeepAliveRequests() {
125+
public @Nullable Integer getMaxKeepAliveRequests() {
124126
return this.maxKeepAliveRequests;
125127
}
126128

127-
public void setMaxKeepAliveRequests(Integer maxKeepAliveRequests) {
129+
public void setMaxKeepAliveRequests(@Nullable Integer maxKeepAliveRequests) {
128130
this.maxKeepAliveRequests = maxKeepAliveRequests;
129131
}
130132

@@ -136,11 +138,11 @@ public void setValidateHeaders(boolean validateHeaders) {
136138
this.validateHeaders = validateHeaders;
137139
}
138140

139-
public Duration getIdleTimeout() {
141+
public @Nullable Duration getIdleTimeout() {
140142
return this.idleTimeout;
141143
}
142144

143-
public void setIdleTimeout(Duration idleTimeout) {
145+
public void setIdleTimeout(@Nullable Duration idleTimeout) {
144146
this.idleTimeout = idleTimeout;
145147
}
146148

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/autoconfigure/ReactorNettyProperties.java

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

1919
import java.time.Duration;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.context.properties.ConfigurationProperties;
2224

2325
/**
@@ -32,13 +34,13 @@ public class ReactorNettyProperties {
3234
/**
3335
* Amount of time to wait before shutting down resources.
3436
*/
35-
private Duration shutdownQuietPeriod;
37+
private @Nullable Duration shutdownQuietPeriod;
3638

37-
public Duration getShutdownQuietPeriod() {
39+
public @Nullable Duration getShutdownQuietPeriod() {
3840
return this.shutdownQuietPeriod;
3941
}
4042

41-
public void setShutdownQuietPeriod(Duration shutdownQuietPeriod) {
43+
public void setShutdownQuietPeriod(@Nullable Duration shutdownQuietPeriod) {
4244
this.shutdownQuietPeriod = shutdownQuietPeriod;
4345
}
4446

module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/autoconfigure/actuate/web/server/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 Reactor Netty actuator web concerns.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.reactor.netty.autoconfigure.actuate.web.server;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)