From 2ad911f93275a174ee167274ec7b467a7cee8141 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Tue, 27 Jan 2026 21:18:36 +0530 Subject: [PATCH] update code comment in test --- .../channels/Selector/ConnectionRefusedMessage.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/jdk/java/nio/channels/Selector/ConnectionRefusedMessage.java b/test/jdk/java/nio/channels/Selector/ConnectionRefusedMessage.java index f59740f6347..5e7b6395a66 100644 --- a/test/jdk/java/nio/channels/Selector/ConnectionRefusedMessage.java +++ b/test/jdk/java/nio/channels/Selector/ConnectionRefusedMessage.java @@ -104,17 +104,18 @@ class ConnectionRefusedMessage { // Try to find a suitable port to provoke a "Connection Refused" error. private static InetSocketAddress findSuitableRefusedAddress() throws IOException { final InetAddress loopbackAddr = InetAddress.getLoopbackAddress(); - // port 47 is reserved - there should be nothing listening on it + // Ports 47, 51, 61 are in the IANA reserved port list, and + // are currently unassigned to any specific service. + // We use them here on the assumption that there won't be + // any service listening on them. InetSocketAddress destAddr = new InetSocketAddress(loopbackAddr, 47); try (SocketChannel sc1 = SocketChannel.open(destAddr)) { - // If we manage to connect, let's try to use some other - // port. - // port 51 is reserved too - there should be nothing there. + // we managed to connect (unexpectedly), let's try the next reserved port destAddr = new InetSocketAddress(loopbackAddr, 51); try (SocketChannel sc2 = SocketChannel.open(destAddr)) { } - // OK, last attempt... - // port 61 is reserved too - there should be nothing there. + // we managed to connect (unexpectedly again), let's try the next reserved port + // as a last attempt destAddr = new InetSocketAddress(loopbackAddr, 61); try (SocketChannel sc3 = SocketChannel.open(destAddr)) { }