Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Commit 1f3cbe4

Browse files
committed
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
1 parent 6b5655a commit 1f3cbe4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/jdk/java/net/Socket/B8312065.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public static void main(String[] args) throws Exception {
7373

7474
try {
7575
Socket socket = new Socket();
76-
// There is no good way to mock SocketTimeoutException, just assume 192.168.255.255 is not in use
77-
socket.connect(new InetSocketAddress("192.168.255.255", 8080), timeoutMillis);
76+
// There is no good way to mock SocketTimeoutException, use reserved IP from https://www.rfc-editor.org/rfc/rfc5737
77+
socket.connect(new InetSocketAddress("192.0.2.1", 8080), timeoutMillis);
7878
} catch (SocketTimeoutException e) {
7979
long duration = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
8080
if (duration >= timeoutMillis) {

0 commit comments

Comments
 (0)