SonarSource/sonarqube · error · MessageException

Entries in property %s must not mix 'host:port' and 'host'.

Error message

Entries in property %s must not mix 'host:port' and 'host'. Provide hosts without port only or hosts with port only.

What it means

For Elasticsearch host lists in cluster mode, all entries must be uniform: either every entry carries an explicit port ('host:port') or none do. ensureEitherPortsAreProvidedOrOnlyHosts detects a mixed list — some entries with ports, some without — and throws, since mixing would make the effective port selection ambiguous.

Source

Thrown at server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java:225

    if (!loopbackAddresses.isEmpty()) {
      throw new MessageException(format("Property %s must not contain a loopback address: %s", property.getKey(),
        loopbackAddresses.stream().map(AddressAndPort::getHost).sorted().collect(Collectors.joining(", "))));
    }
  }

  private void ensureLocalButNotLoopbackAddress(Property property, AddressAndPort addressAndPort) {
    String host = addressAndPort.getHost();
    if (!network.isLocal(host) || network.isLoopback(host)) {
      throw new MessageException(format("Property %s must be a local non-loopback address: %s", property.getKey(), addressAndPort.getHost()));
    }
  }

  private static void ensureEitherPortsAreProvidedOrOnlyHosts(Property property, Set<AddressAndPort> addressAndPorts) {
    Set<AddressAndPort> hostsWithoutPort = addressAndPorts.stream()
      .filter(t -> !t.hasPort())
      .collect(toSet());
    if (!hostsWithoutPort.isEmpty() && hostsWithoutPort.size() != addressAndPorts.size()) {
      throw new MessageException(format("Entries in property %s must not mix 'host:port' and 'host'. Provide hosts without port only or hosts with port only.", property.getKey()));
    }
  }

  private static class AddressAndPort {
    private static final int NO_PORT = -1;

    /**
     * the host from setting, can be a hostname or an IP address
     */
    private final String host;
    private final int port;

    private AddressAndPort(String host, @Nullable Integer port) {
      this.host = host;
      this.port = port == null ? NO_PORT : port;
    }

    public String getHost() {

View on GitHub (pinned to 184c821202)

Solutions

  1. Make all entries in the property consistent: either append the port to every host (host:port) or remove ports from all.
  2. When relying on the default port, ensure every entry is a bare host so the default is applied uniformly.
  3. Re-check the list after automation/template updates — partial regeneration often causes the mix.

Example fix

// before (conf/sonar.properties)
sonar.cluster.es.hosts=es1.internal:9001,es2.internal

// after
sonar.cluster.es.hosts=es1.internal:9001,es2.internal:9001
Defensive patterns

Strategy: validation

Validate before calling

// shell: all es.hosts entries must uniformly have (or lack) a port
hosts=$(grep -E '^sonar\.cluster\.es\.hosts=' conf/sonar.properties | cut -d= -f2 | tr ',' '\n')
with=$(echo "$hosts" | grep -c ':'); total=$(echo "$hosts" | grep -c .)
[ "$with" -gt 0 ] && [ "$with" -ne "$total" ] && echo "Mixed host and host:port entries" && exit 1
true

Prevention

When it happens

Trigger: checkClusterEsHosts parses sonar.cluster.es.hosts (or sonar.cluster.search.hosts with ports) into AddressAndPort entries; it throws when at least one entry lacks a port (hasPort()==false) while other entries in the same property do have one.

Common situations: Editing sonar.cluster.es.hosts to add a new node and forgetting to append its port; mixing DNS service names (which include ports) with bare hostnames; hand-written lists copied from different doc versions.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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