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

Commit

Permalink
8324234: Use reserved IP for java.net testing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luhenry committed Jan 22, 2024
1 parent 6b5655a commit 1f3cbe4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/jdk/java/net/Socket/B8312065.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1f3cbe4

Please sign in to comment.