Skip to content

ConnectorServerTest fails on macOS, because InetAddress.getLocalHost().isLoopbackAddress() is true #13425

@afarber

Description

@afarber

Jetty version(s)
Jetty 12.0.x

Jetty Environment
core

Java version/vendor (use: java -version)
openjdk version "21.0.8" 2025-07-15
OpenJDK Runtime Environment Homebrew (build 21.0.8)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.8, mixed mode, sharing)

OS type/version
macOS 15.5 (24F74)

Description
Good evening, the following 3 tests fail, when I run "mvn install" on my Macbook Air M1 with Homebrew OpenJDK 21, because (differently from Linux) InetAddress.getLocalHost() is same as InetAddress.getLoopbackAddress():

[ERROR] Tests run: 11, Failures: 3, Errors: 1, Skipped: 0, Time elapsed: 0.594 s <<< FAILURE! -- in org.eclipse.jetty.jmx.ConnectorServerTest
[ERROR] org.eclipse.jetty.jmx.ConnectorServerTest.testNoRegistryHostBindsToHost -- Time elapsed: 0.015 s <<< FAILURE!
org.opentest4j.AssertionFailedError: Expected java.net.ConnectException to be thrown, but nothing was thrown.
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
	at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:73)
	at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:35)
	at org.junit.jupiter.api.Assertions.assertThrows(Assertions.java:3128)
	at [email protected]/org.eclipse.jetty.jmx.ConnectorServerTest.testNoRegistryHostBindsToHost(ConnectorServerTest.java:79)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

[ERROR] org.eclipse.jetty.jmx.ConnectorServerTest.testNoRMIHostBindsToHost -- Time elapsed: 0.010 s <<< FAILURE!
org.opentest4j.AssertionFailedError: Expected java.net.ConnectException to be thrown, but nothing was thrown.
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
	at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:73)
	at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:35)
	at org.junit.jupiter.api.Assertions.assertThrows(Assertions.java:3128)
	at [email protected]/org.eclipse.jetty.jmx.ConnectorServerTest.testNoRMIHostBindsToHost(ConnectorServerTest.java:147)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

[ERROR] org.eclipse.jetty.jmx.ConnectorServerTest.testNoRegistryHostNonDefaultRegistryPort -- Time elapsed: 0.014 s <<< FAILURE!
org.opentest4j.AssertionFailedError: Expected java.net.ConnectException to be thrown, but nothing was thrown.
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
	at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:73)
	at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:35)
	at org.junit.jupiter.api.Assertions.assertThrows(Assertions.java:3128)
	at [email protected]/org.eclipse.jetty.jmx.ConnectorServerTest.testNoRegistryHostNonDefaultRegistryPort(ConnectorServerTest.java:97)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

How to reproduce?

cd jetty-core/jetty-jmx && mvn clean test -Dtest=ConnectorServerTest -Dmaven.build.cache.enabled=false

Also, the following Java program TestInetAddress.java:

import java.net.InetAddress;

public class TestInetAddress {
    public static void main(String[] args) throws Exception {
        InetAddress localHost = InetAddress.getLocalHost();
        InetAddress loopback = InetAddress.getLoopbackAddress();
        
        System.out.println("Local host: " + localHost + " (" + localHost.getHostAddress() + ")");
        System.out.println("Loopback: " + loopback + " (" + loopback.getHostAddress() + ")");
        System.out.println("Local host is loopback: " + localHost.isLoopbackAddress());
        System.out.println("Local host canonical name: " + localHost.getCanonicalHostName());
    }
}

Prints on macOS 15.5 (my dev Macbook):

Local host: mba.local/127.0.0.1 (127.0.0.1)
Loopback: localhost/127.0.0.1 (127.0.0.1)
Local host is loopback: true
Local host canonical name: localhost

Prints on Rocky Linux 8.10 (my server at Hetzner):

Local host: www/95.216.113.110 (95.216.113.110)
Loopback: localhost/127.0.0.1 (127.0.0.1)
Local host is loopback: false
Local host canonical name: www

Here are the logs (please wait for my upcoming PR):

ConnectorServerTest-fails.txt
ConnectorServerTest-fixed.txt

(The fixed log shows that the 3 tests has been fixed and only the unrelated testJMXOverTLS is still failing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugFor general bugs on Jetty side

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions