Skip to content

Commit edc4c9e

Browse files
committed
Add nullability annotations to module/spring-boot-jetty
See gh-46587
1 parent df8b098 commit edc4c9e

22 files changed

+104
-54
lines changed

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/ConfigurableJettyWebServerFactory.java

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

1919
import org.eclipse.jetty.server.Server;
2020
import org.eclipse.jetty.util.thread.ThreadPool;
21+
import org.jspecify.annotations.Nullable;
2122

2223
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
2324

@@ -41,7 +42,7 @@ public interface ConfigurableJettyWebServerFactory extends ConfigurableWebServer
4142
* {@code null} (default), the {@link Server} creates a {@link ThreadPool} implicitly.
4243
* @param threadPool the ThreadPool to be used
4344
*/
44-
void setThreadPool(ThreadPool threadPool);
45+
void setThreadPool(@Nullable ThreadPool threadPool);
4546

4647
/**
4748
* Set the number of selector threads to use.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.boot.web.server.GracefulShutdownCallback;
3131
import org.springframework.boot.web.server.GracefulShutdownResult;
32+
import org.springframework.util.Assert;
3233
import org.springframework.util.ReflectionUtils;
3334

3435
/**
@@ -70,10 +71,12 @@ private void shutdown(Connector connector, boolean getResult) {
7071
}
7172
catch (NoSuchMethodError ex) {
7273
Method shutdown = ReflectionUtils.findMethod(connector.getClass(), "shutdown");
74+
Assert.state(shutdown != null, "'shutdown' must not be null");
7375
result = (Future<Void>) ReflectionUtils.invokeMethod(shutdown, connector);
7476
}
7577
if (getResult) {
7678
try {
79+
Assert.state(result != null, "'result' must not be null");
7780
result.get();
7881
}
7982
catch (InterruptedException ex) {

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/JettyWebServer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.eclipse.jetty.server.Server;
3333
import org.eclipse.jetty.server.handler.ContextHandler;
3434
import org.eclipse.jetty.server.handler.StatisticsHandler;
35+
import org.jspecify.annotations.Nullable;
3536

3637
import org.springframework.boot.jetty.reactive.JettyReactiveWebServerFactory;
3738
import org.springframework.boot.web.server.GracefulShutdownCallback;
@@ -65,7 +66,7 @@ public class JettyWebServer implements WebServer {
6566

6667
private final boolean autoStart;
6768

68-
private final GracefulShutdown gracefulShutdown;
69+
private final @Nullable GracefulShutdown gracefulShutdown;
6970

7071
private Connector[] connectors;
7172

@@ -92,19 +93,19 @@ public JettyWebServer(Server server, boolean autoStart) {
9293
initialize();
9394
}
9495

95-
private GracefulShutdown createGracefulShutdown(Server server) {
96+
private @Nullable GracefulShutdown createGracefulShutdown(Server server) {
9697
StatisticsHandler statisticsHandler = findStatisticsHandler(server);
9798
if (statisticsHandler == null) {
9899
return null;
99100
}
100101
return new GracefulShutdown(server, statisticsHandler::getRequestsActive);
101102
}
102103

103-
private StatisticsHandler findStatisticsHandler(Server server) {
104+
private @Nullable StatisticsHandler findStatisticsHandler(Server server) {
104105
return findStatisticsHandler(server.getHandler());
105106
}
106107

107-
private StatisticsHandler findStatisticsHandler(Handler handler) {
108+
private @Nullable StatisticsHandler findStatisticsHandler(Handler handler) {
108109
if (handler instanceof StatisticsHandler statisticsHandler) {
109110
return statisticsHandler;
110111
}
@@ -209,7 +210,7 @@ private String getProtocols(Connector connector) {
209210
return " (" + StringUtils.collectionToDelimitedString(protocols, ", ") + ")";
210211
}
211212

212-
private String getContextPath() {
213+
private @Nullable String getContextPath() {
213214
List<ContextHandler> imperativeContextHandlers = this.server.getHandlers()
214215
.stream()
215216
.map(this::findContextHandler)
@@ -222,7 +223,7 @@ private String getContextPath() {
222223
return imperativeContextHandlers.stream().map(ContextHandler::getContextPath).collect(Collectors.joining(" "));
223224
}
224225

225-
private ContextHandler findContextHandler(Handler handler) {
226+
private @Nullable ContextHandler findContextHandler(Handler handler) {
226227
while (handler instanceof Handler.Wrapper handlerWrapper) {
227228
if (handler instanceof ContextHandler contextHandler) {
228229
return contextHandler;

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/JettyWebServerFactory.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import org.eclipse.jetty.server.ServerConnector;
3939
import org.eclipse.jetty.util.thread.Scheduler;
4040
import org.eclipse.jetty.util.thread.ThreadPool;
41+
import org.jspecify.annotations.Nullable;
4142

4243
import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory;
44+
import org.springframework.boot.web.server.Ssl;
4345
import org.springframework.util.Assert;
4446
import org.springframework.util.StringUtils;
4547

@@ -54,7 +56,7 @@ public class JettyWebServerFactory extends AbstractConfigurableWebServerFactory
5456

5557
private int acceptors = -1;
5658

57-
private ThreadPool threadPool;
59+
private @Nullable ThreadPool threadPool;
5860

5961
private int selectors = -1;
6062

@@ -160,12 +162,12 @@ public void addConfigurations(Configuration... configurations) {
160162
* Returns a Jetty {@link ThreadPool} that should be used by the {@link Server}.
161163
* @return a Jetty {@link ThreadPool} or {@code null}
162164
*/
163-
public ThreadPool getThreadPool() {
165+
public @Nullable ThreadPool getThreadPool() {
164166
return this.threadPool;
165167
}
166168

167169
@Override
168-
public void setThreadPool(ThreadPool threadPool) {
170+
public void setThreadPool(@Nullable ThreadPool threadPool) {
169171
this.threadPool = threadPool;
170172
}
171173

@@ -182,8 +184,8 @@ protected AbstractConnector createConnector(InetSocketAddress address, Server se
182184
return this.createConnector(address, server, null, null, null);
183185
}
184186

185-
protected AbstractConnector createConnector(InetSocketAddress address, Server server, Executor executor,
186-
Scheduler scheduler, ByteBufferPool pool) {
187+
protected AbstractConnector createConnector(InetSocketAddress address, Server server, @Nullable Executor executor,
188+
@Nullable Scheduler scheduler, @Nullable ByteBufferPool pool) {
187189
HttpConfiguration httpConfiguration = new HttpConfiguration();
188190
httpConfiguration.setSendServerVersion(false);
189191
List<ConnectionFactory> connectionFactories = new ArrayList<>();
@@ -200,8 +202,10 @@ protected AbstractConnector createConnector(InetSocketAddress address, Server se
200202
}
201203

202204
protected void customizeSsl(Server server, InetSocketAddress address) {
203-
Assert.state(getSsl().getServerNameBundles().isEmpty(), "Server name SSL bundles are not supported with Jetty");
204-
new SslServerCustomizer(getHttp2(), address, getSsl().getClientAuth(), getSslBundle()).customize(server);
205+
Ssl ssl = getSsl();
206+
Assert.state(ssl != null, "'ssl' must not be null");
207+
Assert.state(ssl.getServerNameBundles().isEmpty(), "Server name SSL bundles are not supported with Jetty");
208+
new SslServerCustomizer(getHttp2(), address, ssl.getClientAuth(), getSslBundle()).customize(server);
205209
}
206210

207211
protected Handler addHandlerWrappers(Handler handler) {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.jetty.server.ServerConnector;
3232
import org.eclipse.jetty.server.SslConnectionFactory;
3333
import org.eclipse.jetty.util.ssl.SslContextFactory;
34+
import org.jspecify.annotations.Nullable;
3435

3536
import org.springframework.boot.ssl.SslBundle;
3637
import org.springframework.boot.ssl.SslBundleKey;
@@ -52,15 +53,16 @@
5253
*/
5354
class SslServerCustomizer implements JettyServerCustomizer {
5455

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

5758
private final InetSocketAddress address;
5859

59-
private final ClientAuth clientAuth;
60+
private final @Nullable ClientAuth clientAuth;
6061

6162
private final SslBundle sslBundle;
6263

63-
SslServerCustomizer(Http2 http2, InetSocketAddress address, ClientAuth clientAuth, SslBundle sslBundle) {
64+
SslServerCustomizer(@Nullable Http2 http2, InetSocketAddress address, @Nullable ClientAuth clientAuth,
65+
SslBundle sslBundle) {
6466
this.address = address;
6567
this.clientAuth = clientAuth;
6668
this.sslBundle = sslBundle;
@@ -156,7 +158,7 @@ private boolean isConscryptPresent() {
156158
* @param factory the Jetty {@link Server SslContextFactory.Server}.
157159
* @param clientAuth the client authentication mode
158160
*/
159-
protected void configureSsl(SslContextFactory.Server factory, ClientAuth clientAuth) {
161+
protected void configureSsl(SslContextFactory.Server factory, @Nullable ClientAuth clientAuth) {
160162
SslBundleKey key = this.sslBundle.getKey();
161163
SslOptions options = this.sslBundle.getOptions();
162164
SslStoreBundle stores = this.sslBundle.getStores();
@@ -186,7 +188,7 @@ protected void configureSsl(SslContextFactory.Server factory, ClientAuth clientA
186188
}
187189
}
188190

189-
private void configureSslClientAuth(SslContextFactory.Server factory, ClientAuth clientAuth) {
191+
private void configureSslClientAuth(SslContextFactory.Server factory, @Nullable ClientAuth clientAuth) {
190192
factory.setWantClientAuth(clientAuth == ClientAuth.WANT || clientAuth == ClientAuth.NEED);
191193
factory.setNeedClientAuth(clientAuth == ClientAuth.NEED);
192194
}

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/autoconfigure/JettyServerProperties.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.time.Duration;
2020
import java.util.List;
2121

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

@@ -66,7 +68,7 @@ public class JettyServerProperties {
6668
/**
6769
* Time that the connection can be idle before it is closed.
6870
*/
69-
private Duration connectionIdleTimeout;
71+
private @Nullable Duration connectionIdleTimeout;
7072

7173
/**
7274
* Maximum size of the HTTP response header.
@@ -113,11 +115,11 @@ public void setMaxFormKeys(int maxFormKeys) {
113115
this.maxFormKeys = maxFormKeys;
114116
}
115117

116-
public Duration getConnectionIdleTimeout() {
118+
public @Nullable Duration getConnectionIdleTimeout() {
117119
return this.connectionIdleTimeout;
118120
}
119121

120-
public void setConnectionIdleTimeout(Duration connectionIdleTimeout) {
122+
public void setConnectionIdleTimeout(@Nullable Duration connectionIdleTimeout) {
121123
this.connectionIdleTimeout = connectionIdleTimeout;
122124
}
123125

@@ -156,17 +158,17 @@ public static class Accesslog {
156158
* Custom log format, see org.eclipse.jetty.server.CustomRequestLog. If defined,
157159
* overrides the "format" configuration key.
158160
*/
159-
private String customFormat;
161+
private @Nullable String customFormat;
160162

161163
/**
162164
* Log filename. If not specified, logs redirect to "System.err".
163165
*/
164-
private String filename;
166+
private @Nullable String filename;
165167

166168
/**
167169
* Date format to place in log file name.
168170
*/
169-
private String fileDateFormat;
171+
private @Nullable String fileDateFormat;
170172

171173
/**
172174
* Number of days before rotated log files are deleted.
@@ -181,7 +183,7 @@ public static class Accesslog {
181183
/**
182184
* Request paths that should not be logged.
183185
*/
184-
private List<String> ignorePaths;
186+
private @Nullable List<String> ignorePaths;
185187

186188
public boolean isEnabled() {
187189
return this.enabled;
@@ -199,27 +201,27 @@ public void setFormat(Accesslog.Format format) {
199201
this.format = format;
200202
}
201203

202-
public String getCustomFormat() {
204+
public @Nullable String getCustomFormat() {
203205
return this.customFormat;
204206
}
205207

206-
public void setCustomFormat(String customFormat) {
208+
public void setCustomFormat(@Nullable String customFormat) {
207209
this.customFormat = customFormat;
208210
}
209211

210-
public String getFilename() {
212+
public @Nullable String getFilename() {
211213
return this.filename;
212214
}
213215

214-
public void setFilename(String filename) {
216+
public void setFilename(@Nullable String filename) {
215217
this.filename = filename;
216218
}
217219

218-
public String getFileDateFormat() {
220+
public @Nullable String getFileDateFormat() {
219221
return this.fileDateFormat;
220222
}
221223

222-
public void setFileDateFormat(String fileDateFormat) {
224+
public void setFileDateFormat(@Nullable String fileDateFormat) {
223225
this.fileDateFormat = fileDateFormat;
224226
}
225227

@@ -239,11 +241,11 @@ public void setAppend(boolean append) {
239241
this.append = append;
240242
}
241243

242-
public List<String> getIgnorePaths() {
244+
public @Nullable List<String> getIgnorePaths() {
243245
return this.ignorePaths;
244246
}
245247

246-
public void setIgnorePaths(List<String> ignorePaths) {
248+
public void setIgnorePaths(@Nullable List<String> ignorePaths) {
247249
this.ignorePaths = ignorePaths;
248250
}
249251

@@ -299,7 +301,7 @@ public static class Threads {
299301
* Maximum capacity of the thread pool's backing queue. A default is computed
300302
* based on the threading configuration.
301303
*/
302-
private Integer maxQueueCapacity;
304+
private @Nullable Integer maxQueueCapacity;
303305

304306
/**
305307
* Maximum thread idle time.
@@ -338,11 +340,11 @@ public Integer getMax() {
338340
return this.max;
339341
}
340342

341-
public Integer getMaxQueueCapacity() {
343+
public @Nullable Integer getMaxQueueCapacity() {
342344
return this.maxQueueCapacity;
343345
}
344346

345-
public void setMaxQueueCapacity(Integer maxQueueCapacity) {
347+
public void setMaxQueueCapacity(@Nullable Integer maxQueueCapacity) {
346348
this.maxQueueCapacity = maxQueueCapacity;
347349
}
348350

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/autoconfigure/JettyThreadPool.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import org.eclipse.jetty.util.BlockingArrayQueue;
2323
import org.eclipse.jetty.util.thread.QueuedThreadPool;
2424
import org.eclipse.jetty.util.thread.ThreadPool;
25+
import org.jspecify.annotations.Nullable;
26+
27+
import org.springframework.lang.Contract;
2528

2629
/**
2730
* Creates a {@link ThreadPool} for Jetty, applying
@@ -44,7 +47,8 @@ static QueuedThreadPool create(JettyServerProperties.Threads properties) {
4447
return new QueuedThreadPool(maxThreadCount, minThreadCount, threadIdleTimeout, queue);
4548
}
4649

47-
private static BlockingQueue<Runnable> determineBlockingQueue(Integer maxQueueCapacity) {
50+
@Contract("!null -> !null")
51+
private static @Nullable BlockingQueue<Runnable> determineBlockingQueue(@Nullable Integer maxQueueCapacity) {
4852
if (maxQueueCapacity == null) {
4953
return null;
5054
}

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

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/autoconfigure/metrics/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 Jetty metrics.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.jetty.autoconfigure.metrics;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/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 Jetty.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.jetty.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)