Note
[BUG] 8371092: NullPointerException in AltServiceUsageTest.afterClass test method
I addressed the warm boot issue that occurs when closing the channel after a test.
Overview#
In the AltServiceUsageTest class for the net system, a field named DatagramChannel udpNotResponding is retained during initialization1. This DatagramChannel is closed at the end of the test (i.e., when the test class is destroyed)2.
Under normal circumstances, the flow is preparation of origin and alternative servers → creation of channels → testing → destruction of channels, with no particular issues.
However, on line 853, if the addresses of the origin server and the alternative server are identical, the channel is not prepared (=not initialized). In this case, since the channel remains uninitialized, there is a risk that a NullPointerException will occur when attempting to close it4.
Discovered on JBS in 2026/11/02#
This bug was discovered on JBS and verified locally. The suspected bug was reproduced, so I began working on the fix.
The following method is where the issue lies5:
@AfterClass
public void afterClass() throws Exception {
safeStop(originServer);
safeStop(altServer);
udpNotResponding.close();
}
To address this problem, a null check was added to this part. Since udpNotResponding.close(); is called in other places as well, I created a common helper method and called it.
This change has been marked as integrable.
private static void safeStop(final HttpTestServer server) {
if (server == null) {
return;
}
final InetSocketAddress serverAddr = server.getAddress();
try {
System.out.println("Stopping server " + serverAddr);
server.stop();
} catch (Exception e) {
System.err.println("Ignoring exception: " + e.getMessage() + " that occurred during stop of server: " + serverAddr);
}
}
By introducing this change and replacing the call site, I completed the fix6.
Reviewed on 2025/11/03#
The changes were reviewed by Daniel Fuchs7 who approved them. Additionally, he provided the following comment:
Please make sure to run the test locally before integrating. Networking tests are not run by github actions.
Integration Requested on 2025/11/04#
After confirming the previous review and running local tests, I verified that they passed and marked them as integrable.
Integrated on 2025/11/05#
With Fuchs7's /sponsor, the changes were integrated into JDK under commit 2f455ed8.
Footnotes#
-
jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkJDK main-line development https://openjdk.org/projects/jdk - jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkGitHub
↩
-
jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkJDK main-line development https://openjdk.org/projects/jdk - jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkGitHub
↩
-
jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkJDK main-line development https://openjdk.org/projects/jdk - jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkGitHub
↩
-
jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkJDK main-line development https://openjdk.org/projects/jdk - jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkGitHub
↩
-
jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkJDK main-line development https://openjdk.org/projects/jdk - jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkGitHub
↩
-
jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkJDK main-line development https://openjdk.org/projects/jdk - jdk/test/jdk/java/net/httpclient/AltServiceUsageTest.java at 48d21b50faed61eaa4f1d115531a21d0c29a5dff · openjdk/jdkGitHub
↩
-
https://openjdk.org/census#dfuchsopenjdk.org↩ ↩2
-
8371092: NullPointerException in AltServiceUsageTest.afterClass() test · openjdk/jdk@2f455edJDK main-line development https://openjdk.org/projects/jdk - 8371092: NullPointerException in AltServiceUsageTest.afterClass() test · openjdk/jdk@2f455edGitHub
↩