RFR: 8313997: The jdi/ListeningConnector/startListening/startlis001 may fail if the hosts file is modified
Aleksey Shipilev
shade at openjdk.org
Tue Sep 12 17:17:43 UTC 2023
On Wed, 9 Aug 2023 07:46:58 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
> The test uses this code to create a list of valid addresses for the localhost:
>
> String hostname = "localhost";
> List<String> validAddresses = new LinkedList<>();
> validAddresses.add(hostname);
> Arrays.stream(InetAddress.getAllByName(hostname))
> .forEach(address -> validAddresses.add(address.getHostAddress()));
>
> It does not work properly if the custom name is set for the 127.0.01 via /etc/hosts file. In that case, the address returned by the "startListen()" will be "SomeCustomName:port", for example we can return it here:
> https://github.com/openjdk/jdk/blob/360f65d7b15b327e2f160c42f318945cc6548bda/src/jdk.jdi/share/classes/com/sun/tools/jdi/SocketTransportService.java#L82
I agree with @mrserb: since JDI's `SocketListenKey.address()` already returns `InetAddress.getLocalHost()`, we need to match it in the tests.
The machine configuration is not very relevant here, and matching the hostname just hides the discrepancy between product and test code.
-------------
Marked as reviewed by shade (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/15203#pullrequestreview-1622752217
More information about the serviceability-dev
mailing list