SonarSource/sonarqube · error · IllegalStateException

Can not retrieve network interfaces

Error message

Can not retrieve network interfaces

What it means

getLocalInetAddress enumerates NetworkInterfaces and their InetAddresses filtered by a predicate. A SocketException during enumeration is wrapped into IllegalStateException 'Can not retrieve network interfaces'.

Solutions

  1. Fix host/container networking so interfaces can be enumerated
  2. Verify `NetworkInterface.getNetworkInterfaces()` returns non-null on the host
  3. Restart the network stack or the container
  4. Inspect the wrapped SocketException cause

Example fix

null
Defensive patterns

Strategy: try-catch

Try / catch

try {
  InetAddress addr = networkUtils.getLocalInetAddress(a -> true);
} catch (IllegalStateException e) {
  LOGGER.error("Network interfaces unavailable; check container/host networking", e);
}

Prevention

When it happens

Trigger: NetworkInterface.getNetworkInterfaces()/getInetAddresses() throwing SocketException — e.g. network stack unavailable or restricted at JVM startup.

Common situations: Containers with missing /proc/net or restricted netns; VPN or virtual adapters in a broken state; minimal OS images lacking networking setup.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/cfb63258f4367bbb. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java:169

    boolean ipv6Preferred = Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses"));

    if (inetAddress.isEmpty() || inetAddress.get().isLoopbackAddress()) {
      return ipv6Preferred;
    }
    return inetAddress.get() instanceof Inet6Address;
  }

  @Override
  public Optional<InetAddress> getLocalInetAddress(Predicate<InetAddress> predicate) {
    try {
      return Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
        .flatMap(ni -> Collections.list(ni.getInetAddresses()).stream())
        .filter(a -> a.getHostAddress() != null)
        .filter(predicate)
        .findFirst();
    } catch (SocketException e) {
      LOG.trace("getLocalInetAddress(Predicate<InetAddress>) failed", e);
      throw new IllegalStateException("Can not retrieve network interfaces", e);
    }
  }
}

View on GitHub (pinned to 184c821202)