{"record":{"id":"17f65a1f01b21a2a","repo":"SonarSource/sonarqube","slug":"http-port-s-is-invalid","errorCode":null,"errorMessage":"HTTP port %s is invalid","messagePattern":"HTTP port (.+?) is invalid","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatHttpConnectorFactory.java","lineNumber":62,"sourceCode":"  public Connector createConnector(Props props) {\n    Connector connector = new Connector(HTTP_PROTOCOL);\n    connector.setURIEncoding(\"UTF-8\");\n    connector.setProperty(\"address\", props.value(WEB_HOST.getKey(), \"0.0.0.0\"));\n    connector.setProperty(\"socket.soReuseAddress\", \"true\");\n    // See Tomcat configuration reference: https://tomcat.apache.org/tomcat-9.0-doc/config/http.html\n    connector.setProperty(\"relaxedQueryChars\", \"\\\"<>[\\\\]^`{|}\");\n    connector.setProperty(\"maxHttpHeaderSize\", String.valueOf(MAX_HTTP_HEADER_SIZE_BYTES));\n    connector.setMaxPostSize(MAX_POST_SIZE);\n    configurePort(connector, props);\n    configurePool(props, connector);\n    configureCompression(connector);\n    return connector;\n  }\n\n  private static void configurePort(Connector connector, Props props) {\n    int port = props.valueAsInt(WEB_PORT.getKey(), 9000);\n    if (port < 0) {\n      throw new IllegalStateException(format(\"HTTP port %s is invalid\", port));\n    }\n    connector.setPort(port);\n    LOGGER.info(\"Starting Tomcat on port {}\", connector.getPort());\n  }\n\n  private static void configurePool(Props props, Connector connector) {\n    connector.setProperty(\"minSpareThreads\", String.valueOf(props.valueAsInt(WEB_HTTP_MIN_THREADS.getKey(), 5)));\n    connector.setProperty(\"maxThreads\", String.valueOf(props.valueAsInt(WEB_HTTP_MAX_THREADS.getKey(), 50)));\n    connector.setProperty(\"acceptCount\", String.valueOf(props.valueAsInt(WEB_HTTP_ACCEPT_COUNT.getKey(), 25)));\n    connector.setProperty(\"keepAliveTimeout\", String.valueOf(props.valueAsInt(WEB_HTTP_KEEP_ALIVE_TIMEOUT.getKey(), 60000)));\n  }\n\n  private static void configureCompression(Connector connector) {\n    connector.setProperty(\"compression\", \"on\");\n    connector.setProperty(\"compressionMinSize\", \"1024\");\n    connector.setProperty(\"compressibleMimeType\", \"text/html,text/xml,text/plain,text/css,application/json,application/javascript,text/javascript\");\n  }\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver/src/main/java/org/sonar/server/app/TomcatHttpConnectorFactory.java#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set sonar.web.port to a valid value between 1 and 65535 (or 0 for a random free port)","Check sonar.properties and environment overrides for typos or unresolved placeholders in the port value","Remove a duplicate/conflicting sonar.web.port entry that overrides the correct value"],"exampleFix":"// before\nsonar.web.port=-1\n// after\nsonar.web.port=9000","handlingStrategy":"validation","validationCode":"int port = Integer.parseInt(System.getProperty(\"sonar.web.port\", \"9000\"));\nif (port < 0 || port > 65535) throw new IllegalArgumentException(\"sonar.web.port must be 0-65535, got \" + port);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate sonar.web.port in sonar.properties before starting (1-65535)","Avoid unresolved placeholders (${...}) in port config from environment templating","Keep a single authoritative definition of the port to avoid overrides"],"tags":["configuration","port","startup"],"backgroundTag":"invalid-config-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}