From 1f3cbe4f7a4004186a7ccca663ace1d17023d7e7 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 22 Jan 2024 07:45:28 +0000 Subject: [PATCH] 8324234: Use reserved IP for java.net testing Some tests like test/jdk/java/net/Socket/B8312065.java use specific IPs (like 192.168.255.255) taking the assumption that the address is not going to be assigned. This doesn't always hold true, as 192.168.255.255 for example is a valid address. RFC 5737 [1] defines specific ranges of IP addresses that may are reserved for these exact purpose and that will never be assigned. Let's make sure to use an IP in this range, like 192.0.2.1 for example. The specific test test/jdk/java/net/Socket/B8312065.java was introduced with https://git.openjdk.org/jdk17u-dev/pull/1639. [1] https://www.rfc-editor.org/rfc/rfc5737 --- test/jdk/java/net/Socket/B8312065.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/jdk/java/net/Socket/B8312065.java b/test/jdk/java/net/Socket/B8312065.java index 118792eada3..30168aa61bf 100644 --- a/test/jdk/java/net/Socket/B8312065.java +++ b/test/jdk/java/net/Socket/B8312065.java @@ -73,8 +73,8 @@ public static void main(String[] args) throws Exception { try { Socket socket = new Socket(); - // There is no good way to mock SocketTimeoutException, just assume 192.168.255.255 is not in use - socket.connect(new InetSocketAddress("192.168.255.255", 8080), timeoutMillis); + // There is no good way to mock SocketTimeoutException, use reserved IP from https://www.rfc-editor.org/rfc/rfc5737 + socket.connect(new InetSocketAddress("192.0.2.1", 8080), timeoutMillis); } catch (SocketTimeoutException e) { long duration = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); if (duration >= timeoutMillis) {