diff --git a/test/jdk/java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java b/test/jdk/java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java index 073b56d0ea0..b21a47ed1be 100644 --- a/test/jdk/java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java +++ b/test/jdk/java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java @@ -27,8 +27,11 @@ * @summary Verify that expect 100-continue doesn't hang * @library /test/lib * @run junit/othervm HttpURLConnectionExpectContinueTest + * @run junit/othervm -Djava.net.preferIPv4Stack=true HttpURLConnectionExpectContinueTest + * @run junit/othervm -Djava.net.preferIPv6Addresses=true HttpURLConnectionExpectContinueTest */ +import jdk.test.lib.net.URIBuilder; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -73,7 +76,7 @@ public class HttpURLConnectionExpectContinueTest { control.serverSocket = new ServerSocket(); control.serverSocket.setReuseAddress(true); - control.serverSocket.bind(new InetSocketAddress("127.0.0.1", 54321)); + control.serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); Runnable runnable = () -> { while (!control.stop) { try { @@ -419,8 +422,12 @@ public class HttpURLConnectionExpectContinueTest { } // Creates a connection with all the common settings used in each test - private HttpURLConnection createConnection() throws IOException { - URL url = new URL("http://localhost:" + control.serverSocket.getLocalPort()); + private HttpURLConnection createConnection() throws Exception { + URL url = URIBuilder.newBuilder() + .scheme("http") + .loopback() + .port(control.serverSocket.getLocalPort()) + .toURL(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true);