diff --git a/module/spring-boot-jetty/build.gradle b/module/spring-boot-jetty/build.gradle index 273fc2bcbdf..25e314dace7 100644 --- a/module/spring-boot-jetty/build.gradle +++ b/module/spring-boot-jetty/build.gradle @@ -48,6 +48,8 @@ dependencies { testImplementation(testFixtures(project(":core:spring-boot-autoconfigure"))) testImplementation("org.apache.httpcomponents.client5:httpclient5") + testCompileOnly("com.google.code.findbugs:jsr305") + testRuntimeOnly("ch.qos.logback:logback-classic") testRuntimeOnly("io.projectreactor:reactor-test") testRuntimeOnly("io.projectreactor.netty:reactor-netty-http") @@ -61,3 +63,6 @@ test { jvmArgs += "--add-opens=java.base/java.net=ALL-UNNAMED" } +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/SslServerCustomizerTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/SslServerCustomizerTests.java index 32ec00ff73a..93951e9d72c 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/SslServerCustomizerTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/SslServerCustomizerTests.java @@ -96,7 +96,8 @@ class SslServerCustomizerTests { void configureSslWhenSslIsEnabledWithNoKeyStoreAndNotPkcs11ThrowsException() { Ssl ssl = new Ssl(); assertThatIllegalStateException().isThrownBy(() -> { - SslServerCustomizer customizer = new SslServerCustomizer(null, null, null, WebServerSslBundle.get(ssl)); + SslServerCustomizer customizer = new SslServerCustomizer(null, new InetSocketAddress(0), null, + WebServerSslBundle.get(ssl)); customizer.configureSsl(new SslContextFactory.Server(), ssl.getClientAuth()); }).withMessageContaining("SSL is enabled but no trust material is configured"); } @@ -110,7 +111,8 @@ class SslServerCustomizerTests { ssl.setKeyStore("classpath:test.jks"); ssl.setKeyPassword("password"); assertThatIllegalStateException().isThrownBy(() -> { - SslServerCustomizer customizer = new SslServerCustomizer(null, null, null, WebServerSslBundle.get(ssl)); + SslServerCustomizer customizer = new SslServerCustomizer(null, new InetSocketAddress(0), null, + WebServerSslBundle.get(ssl)); customizer.configureSsl(new SslContextFactory.Server(), ssl.getClientAuth()); }).withMessageContaining("must be empty or null for PKCS11 hardware key stores"); } @@ -122,7 +124,8 @@ class SslServerCustomizerTests { ssl.setKeyStoreProvider(MockPkcs11SecurityProvider.NAME); ssl.setKeyStorePassword("1234"); assertThatNoException().isThrownBy(() -> { - SslServerCustomizer customizer = new SslServerCustomizer(null, null, null, WebServerSslBundle.get(ssl)); + SslServerCustomizer customizer = new SslServerCustomizer(null, new InetSocketAddress(0), null, + WebServerSslBundle.get(ssl)); customizer.configureSsl(new SslContextFactory.Server(), ssl.getClientAuth()); }); } diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/JettyWebServerFactoryCustomizerTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/JettyWebServerFactoryCustomizerTests.java index 411fe247109..14a9c85a614 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/JettyWebServerFactoryCustomizerTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/JettyWebServerFactoryCustomizerTests.java @@ -378,7 +378,9 @@ class JettyWebServerFactoryCustomizerTests { } private BlockingQueue getQueue(ThreadPool threadPool) { - return ReflectionTestUtils.invokeMethod(threadPool, "getQueue"); + BlockingQueue queue = ReflectionTestUtils.invokeMethod(threadPool, "getQueue"); + assertThat(queue).isNotNull(); + return queue; } private void bind(String... inlinedProperties) { diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/metrics/JettyMetricsAutoConfigurationTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/metrics/JettyMetricsAutoConfigurationTests.java index bcc972861f3..d0ac3f886c4 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/metrics/JettyMetricsAutoConfigurationTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/metrics/JettyMetricsAutoConfigurationTests.java @@ -217,7 +217,7 @@ class JettyMetricsAutoConfigurationTests { } private ApplicationStartedEvent createApplicationStartedEvent(ConfigurableApplicationContext context) { - return new ApplicationStartedEvent(new SpringApplication(), null, context, null); + return new ApplicationStartedEvent(new SpringApplication(), new String[0], context, null); } @Configuration(proxyBeanMethods = false) diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/reactive/JettyReactiveWebServerAutoConfigurationTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/reactive/JettyReactiveWebServerAutoConfigurationTests.java index 9c665cb64a3..abfb38c3abe 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/reactive/JettyReactiveWebServerAutoConfigurationTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/reactive/JettyReactiveWebServerAutoConfigurationTests.java @@ -76,6 +76,7 @@ class JettyReactiveWebServerAutoConfigurationTests extends AbstractReactiveWebSe this.serverRunner.run((context) -> { WebServer webServer = ((ReactiveWebServerApplicationContext) context.getSourceApplicationContext()) .getWebServer(); + assertThat(webServer).isNotNull(); ServletContextHandler servletContextHandler = (ServletContextHandler) ((StatisticsHandler) ((JettyWebServer) webServer) .getServer() .getHandler()).getHandler(); diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/servlet/JettyServletWebServerAutoConfigurationTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/servlet/JettyServletWebServerAutoConfigurationTests.java index 2a6ecce3cad..56ce0a79407 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/servlet/JettyServletWebServerAutoConfigurationTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/autoconfigure/servlet/JettyServletWebServerAutoConfigurationTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.jetty.autoconfigure.servlet; import java.util.Map; import jakarta.servlet.Filter; +import jakarta.servlet.ServletContext; import org.eclipse.jetty.ee11.websocket.servlet.WebSocketUpgradeFilter; import org.eclipse.jetty.server.Server; import org.junit.jupiter.api.Test; @@ -75,9 +76,11 @@ class JettyServletWebServerAutoConfigurationTests extends AbstractServletWebServ @Test void jettyWebSocketUpgradeFilterIsAddedToServletContex() { - this.serverRunner.run((context) -> assertThat( - context.getServletContext().getFilterRegistration(WebSocketUpgradeFilter.class.getName())) - .isNotNull()); + this.serverRunner.run((context) -> { + ServletContext servletContext = context.getServletContext(); + assertThat(servletContext).isNotNull(); + assertThat(servletContext.getFilterRegistration(WebSocketUpgradeFilter.class.getName())).isNotNull(); + }); } @Test diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/reactive/JettyReactiveWebServerFactoryTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/reactive/JettyReactiveWebServerFactoryTests.java index 59782adfa4c..3948dc53dcd 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/reactive/JettyReactiveWebServerFactoryTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/reactive/JettyReactiveWebServerFactoryTests.java @@ -72,6 +72,7 @@ class JettyReactiveWebServerFactoryTests extends AbstractReactiveWebServerFactor } @Test + @SuppressWarnings("NullAway") // Test null check void setNullServerCustomizersShouldThrowException() { JettyReactiveWebServerFactory factory = getFactory(); assertThatIllegalArgumentException().isThrownBy(() -> factory.setServerCustomizers(null)) @@ -79,6 +80,7 @@ class JettyReactiveWebServerFactoryTests extends AbstractReactiveWebServerFactor } @Test + @SuppressWarnings("NullAway") // Test null check void addNullServerCustomizersShouldThrowException() { JettyReactiveWebServerFactory factory = getFactory(); assertThatIllegalArgumentException() diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/JettyServletWebServerFactoryTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/JettyServletWebServerFactoryTests.java index f37cf6f72ef..a3bf831c1b0 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/JettyServletWebServerFactoryTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/JettyServletWebServerFactoryTests.java @@ -58,6 +58,7 @@ import org.eclipse.jetty.util.ClassMatcher; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ThreadPool; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -123,7 +124,7 @@ class JettyServletWebServerFactoryTests extends AbstractServletWebServerFactoryT } @Override - protected JspServlet getJspServlet() throws Exception { + protected @Nullable JspServlet getJspServlet() throws Exception { WebAppContext context = findWebAppContext((JettyWebServer) this.webServer); ServletHolder holder = context.getServletHandler().getServlet("jsp"); if (holder == null) { @@ -141,7 +142,7 @@ class JettyServletWebServerFactoryTests extends AbstractServletWebServerFactoryT } @Override - protected Charset getCharset(Locale locale) { + protected @Nullable Charset getCharset(Locale locale) { WebAppContext context = findWebAppContext((JettyWebServer) this.webServer); String charsetName = context.getLocaleEncoding(locale); return (charsetName != null) ? Charset.forName(charsetName) : null; @@ -314,7 +315,11 @@ class JettyServletWebServerFactoryTests extends AbstractServletWebServerFactoryT catch (NoSuchMethodError ex) { Method getSslContextFactory = ReflectionUtils.findMethod(connectionFactory.getClass(), "getSslContextFactory"); - return (SslContextFactory) ReflectionUtils.invokeMethod(getSslContextFactory, connectionFactory); + assertThat(getSslContextFactory).isNotNull(); + SslContextFactory sslContextFactory = (SslContextFactory) ReflectionUtils.invokeMethod(getSslContextFactory, + connectionFactory); + assertThat(sslContextFactory).isNotNull(); + return sslContextFactory; } } @@ -528,6 +533,7 @@ class JettyServletWebServerFactoryTests extends AbstractServletWebServerFactoryT // Jetty 10 Method addEventListener = ReflectionUtils.findMethod(context.getClass(), "addEventListener", EventListener.class); + assertThat(addEventListener).isNotNull(); ReflectionUtils.invokeMethod(addEventListener, context, eventListener); } }); diff --git a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/LoaderHidingResourceTests.java b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/LoaderHidingResourceTests.java index 2fcb8939d42..5dc63a45a4e 100644 --- a/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/LoaderHidingResourceTests.java +++ b/module/spring-boot-jetty/src/test/java/org/springframework/boot/jetty/servlet/LoaderHidingResourceTests.java @@ -70,10 +70,14 @@ class LoaderHidingResourceTests { URI warUri = createExampleWar(temp); Resource resource = new PathResourceFactory().newResource(warUri); LoaderHidingResource loaderHidingResource = new LoaderHidingResource(resource, resource); - assertThat(loaderHidingResource.resolve("/assets/image.jpg").exists()).isTrue(); - assertThat(loaderHidingResource.resolve("/assets/image.jpg")).isInstanceOf(LoaderHidingResource.class); - assertThat(loaderHidingResource.resolve("/assets/non-existent.jpg").exists()).isFalse(); - assertThat(loaderHidingResource.resolve("/assets/non-existent.jpg")).isInstanceOf(LoaderHidingResource.class); + Resource image = loaderHidingResource.resolve("/assets/image.jpg"); + assertThat(image).isNotNull(); + assertThat(image.exists()).isTrue(); + assertThat(image).isInstanceOf(LoaderHidingResource.class); + Resource doesntExist = loaderHidingResource.resolve("/assets/non-existent.jpg"); + assertThat(doesntExist).isNotNull(); + assertThat(doesntExist.exists()).isFalse(); + assertThat(doesntExist).isInstanceOf(LoaderHidingResource.class); assertThat(loaderHidingResource.resolve("/org/springframework/boot/Loader.class")).isNull(); } diff --git a/module/spring-boot-web-server/src/testFixtures/java/org/springframework/boot/web/server/servlet/AbstractServletWebServerFactoryTests.java b/module/spring-boot-web-server/src/testFixtures/java/org/springframework/boot/web/server/servlet/AbstractServletWebServerFactoryTests.java index fc0c98b6448..7a82c9f73e2 100644 --- a/module/spring-boot-web-server/src/testFixtures/java/org/springframework/boot/web/server/servlet/AbstractServletWebServerFactoryTests.java +++ b/module/spring-boot-web-server/src/testFixtures/java/org/springframework/boot/web/server/servlet/AbstractServletWebServerFactoryTests.java @@ -106,6 +106,7 @@ import org.awaitility.Awaitility; import org.eclipse.jetty.client.ContentResponse; import org.eclipse.jetty.http2.client.HTTP2Client; import org.eclipse.jetty.http2.client.transport.HttpClientTransportOverHTTP2; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; @@ -1507,7 +1508,7 @@ public abstract class AbstractServletWebServerFactoryTests { protected abstract Map getActualMimeMappings(); - protected abstract Charset getCharset(Locale locale); + protected abstract @Nullable Charset getCharset(Locale locale); protected void addTestTxtFile(ConfigurableServletWebServerFactory factory) throws IOException { FileCopyUtils.copy("test", new FileWriter(new File(this.tempDir, "test.txt"))); @@ -1588,7 +1589,7 @@ public abstract class AbstractServletWebServerFactoryTests { protected abstract ConfigurableServletWebServerFactory getFactory(); - protected abstract org.apache.jasper.servlet.JspServlet getJspServlet() throws Exception; + protected abstract org.apache.jasper.servlet.@Nullable JspServlet getJspServlet() throws Exception; protected ServletContextInitializer exampleServletRegistration() { return new ServletRegistrationBean<>(new ExampleServlet(), "/hello");