SonarSource/sonarqube · error · IllegalStateException

HTTP port %s is invalid

Error message

HTTP port %s is invalid

What it means

TomcatHttpConnectorFactory.configurePort reads sonar.web.port (default 9000) and rejects negative values, since a TCP port must be 0-65535 (0 meaning ephemeral pick). An invalid port aborts connector creation with this IllegalStateException.

Source

Thrown at server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatHttpConnectorFactory.java:62

  public Connector createConnector(Props props) {
    Connector connector = new Connector(HTTP_PROTOCOL);
    connector.setURIEncoding("UTF-8");
    connector.setProperty("address", props.value(WEB_HOST.getKey(), "0.0.0.0"));
    connector.setProperty("socket.soReuseAddress", "true");
    // See Tomcat configuration reference: https://tomcat.apache.org/tomcat-9.0-doc/config/http.html
    connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
    connector.setProperty("maxHttpHeaderSize", String.valueOf(MAX_HTTP_HEADER_SIZE_BYTES));
    connector.setMaxPostSize(MAX_POST_SIZE);
    configurePort(connector, props);
    configurePool(props, connector);
    configureCompression(connector);
    return connector;
  }

  private static void configurePort(Connector connector, Props props) {
    int port = props.valueAsInt(WEB_PORT.getKey(), 9000);
    if (port < 0) {
      throw new IllegalStateException(format("HTTP port %s is invalid", port));
    }
    connector.setPort(port);
    LOGGER.info("Starting Tomcat on port {}", connector.getPort());
  }

  private static void configurePool(Props props, Connector connector) {
    connector.setProperty("minSpareThreads", String.valueOf(props.valueAsInt(WEB_HTTP_MIN_THREADS.getKey(), 5)));
    connector.setProperty("maxThreads", String.valueOf(props.valueAsInt(WEB_HTTP_MAX_THREADS.getKey(), 50)));
    connector.setProperty("acceptCount", String.valueOf(props.valueAsInt(WEB_HTTP_ACCEPT_COUNT.getKey(), 25)));
    connector.setProperty("keepAliveTimeout", String.valueOf(props.valueAsInt(WEB_HTTP_KEEP_ALIVE_TIMEOUT.getKey(), 60000)));
  }

  private static void configureCompression(Connector connector) {
    connector.setProperty("compression", "on");
    connector.setProperty("compressionMinSize", "1024");
    connector.setProperty("compressibleMimeType", "text/html,text/xml,text/plain,text/css,application/json,application/javascript,text/javascript");
  }

View on GitHub (pinned to 184c821202)

Solutions

  1. Set sonar.web.port to a valid value between 1 and 65535 (or 0 for a random free port)
  2. Check sonar.properties and environment overrides for typos or unresolved placeholders in the port value
  3. Remove a duplicate/conflicting sonar.web.port entry that overrides the correct value

Example fix

// before
sonar.web.port=-1
// after
sonar.web.port=9000
Defensive patterns

Strategy: validation

Validate before calling

int port = Integer.parseInt(System.getProperty("sonar.web.port", "9000"));
if (port < 0 || port > 65535) throw new IllegalArgumentException("sonar.web.port must be 0-65535, got " + port);

Prevention

When it happens

Trigger: Setting sonar.web.port to a negative number in sonar.properties, or passing a negative WEB_PORT prop when programmatically building the connector via createConnector.

Common situations: Typo in sonar.properties (e.g. sonar.web.port=-1); environment-variable substitution injecting a placeholder like ${PORT} that parses to a negative or malformed value; copy-paste from another tool's config.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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