From 96b0c2f1015db4ff5aad99b3f24e2b09017558bd Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 29 Oct 2024 09:44:47 +0100 Subject: [PATCH] Do not throw NPE in AfterAll interceptor if application didn't start This is to solve an issue that we can see from time to time in the CI: java.lang.NullPointerException: Cannot invoke "io.quarkus.bootstrap.app.RunningQuarkusApplication.getClassLoader()" because "io.quarkus.test.junit.QuarkusTestExtension.runningQuarkusApplication" is null at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:909) at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:901) at io.quarkus.test.junit.QuarkusTestExtension.interceptAfterAllMethod(QuarkusTestExtension.java:895) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) Suppressed: org.opentest4j.TestAbortedException: Boot failed For instance here: https://github.com/quarkusio/quarkus/pull/43448#issuecomment-2430017790 in the io.quarkus.it.mongodb.BookResourceTest failure. --- .../main/java/io/quarkus/test/junit/QuarkusTestExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index 33e6a6175196d..2cd6963597880 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -888,7 +888,7 @@ public void interceptAfterEachMethod(Invocation invocation, ReflectiveInvo @Override public void interceptAfterAllMethod(Invocation invocation, ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable { - if (isNativeOrIntegrationTest(extensionContext.getRequiredTestClass())) { + if (runningQuarkusApplication == null || isNativeOrIntegrationTest(extensionContext.getRequiredTestClass())) { invocation.proceed(); return; }