{"record":{"id":"9a6c878e1c6cc8f2","repo":"SonarSource/sonarqube","slug":"connect-timeout-must-be-positive-got","errorCode":null,"errorMessage":"Connect timeout must be positive. Got ","messagePattern":"Connect timeout must be positive\\. Got ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java","lineNumber":152,"sourceCode":"  }\n\n  /**\n   * Password used for proxy authentication. It is ignored if\n   * proxy login is not defined (see {@link #setProxyLogin(String)}).\n   * It can be null or empty when login is defined.\n   */\n  public OkHttpClientBuilder setProxyPassword(@Nullable String s) {\n    this.proxyPassword = s;\n    return this;\n  }\n\n  /**\n   * Sets the default connect timeout for new connections. A value of 0 means no timeout.\n   * Default is defined by OkHttp (10 seconds in OkHttp 3.3).\n   */\n  public OkHttpClientBuilder setConnectTimeoutMs(long l) {\n    if (l < 0) {\n      throw new IllegalArgumentException(\"Connect timeout must be positive. Got \" + l);\n    }\n    this.connectTimeoutMs = l;\n    return this;\n  }\n\n  /**\n   * Set credentials that will be passed on every request\n   */\n  public OkHttpClientBuilder setCredentials(String credentials) {\n    this.credentials = credentials;\n    return this;\n  }\n\n  /**\n   * Sets the default read timeout for new connections. A value of 0 means no timeout.\n   * Default is defined by OkHttp (10 seconds in OkHttp 3.3).\n   */\n  public OkHttpClientBuilder setReadTimeoutMs(long l) {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java#L134-L170","documentation":"OkHttpClientBuilder.setConnectTimeoutMs(long) validates its argument and throws IllegalArgumentException when a negative value is passed. Zero is allowed and means 'no timeout'; only negative milliseconds are rejected. This fails fast on invalid builder configuration before an OkHttpClient is created.","triggerScenarios":"Calling setConnectTimeoutMs with any negative long (e.g. setConnectTimeoutMs(-1)), often from configuration code that computed the value dynamically or loaded a negative value from properties/environment, or a later subtraction producing a negative result.","commonSituations":"Config files or env vars containing negative timeout values; arithmetic like now - deadline going negative; unit confusion after conversions; copy-paste of a signed constant.","solutions":["Pass a non-negative value: 0 disables the timeout, positive values are milliseconds","Clamp the configured value before building: Math.max(0, configuredMs)","Validate/correct the source configuration (properties, env var, YAML) that yields the negative number"],"exampleFix":"// before\nbuilder.setConnectTimeoutMs(timeoutMs);\n// after\nbuilder.setConnectTimeoutMs(Math.max(0, timeoutMs));","handlingStrategy":"validation","validationCode":"if (connectTimeoutMs < 0) throw new IllegalArgumentException(\"connectTimeoutMs must be >= 0, got \" + connectTimeoutMs);\nbuilder.setConnectTimeoutMs(Math.max(0, connectTimeoutMs));","typeGuard":null,"tryCatchPattern":"try {\n  builder.setConnectTimeoutMs(cfg.connectTimeoutMs());\n} catch (IllegalArgumentException e) {\n  log.warn(\"Bad connect timeout, using default\", e);\n}\n","preventionTips":["Remember the convention: 0 disables the timeout, -1 is invalid","Sanitize timeout values read from properties/env before building the client","Clamp computed durations with Math.max(0, value)"],"tags":["configuration","timeout","okhttp","builder"],"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-17T15:17:12.973Z"}