{"record":{"id":"8ca89a1806159782","repo":"SonarSource/sonarqube","slug":"response-timeout-must-be-positive-got","errorCode":null,"errorMessage":"Response timeout must be positive. Got ","messagePattern":"Response 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":184,"sourceCode":"  /**\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) {\n    if (l < 0) {\n      throw new IllegalArgumentException(\"Read timeout must be positive. Got \" + l);\n    }\n    this.readTimeoutMs = l;\n    return this;\n  }\n\n  /**\n   * Sets the default response timeout for new connections. A value of 0 means no timeout.\n   * Default is to have no timeout.\n   */\n  public OkHttpClientBuilder setResponseTimeoutMs(long l) {\n    if (l < 0) {\n      throw new IllegalArgumentException(\"Response timeout must be positive. Got \" + l);\n    }\n    this.responseTimeoutMs = l;\n    return this;\n  }\n\n  /**\n   * Set if redirects should be followed or not.\n   * Default is defined by OkHttp (true, follow redirects).\n   */\n  public OkHttpClientBuilder setFollowRedirects(Boolean followRedirects) {\n    this.followRedirects = followRedirects;\n    return this;\n  }\n\n  public OkHttpClient build() {\n    OkHttpClient.Builder builder = new OkHttpClient.Builder();\n    builder.proxy(proxy);\n    if (connectTimeoutMs >= 0) {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java#L166-L202","documentation":"OkHttpClientBuilder.setResponseTimeoutMs(long) throws IllegalArgumentException for negative values, mirroring the other timeout setters. Zero means no response timeout (the default). The check is performed at set time so invalid builder input fails fast before any HTTP call.","triggerScenarios":"Calling setResponseTimeoutMs with a negative long, e.g. a computed value or configuration constant that is negative; wired through HttpConnector's client preparation.","commonSituations":"Using -1 to mean 'unlimited' (correct value is 0); negative results from deadline arithmetic; bad values copied from other HTTP clients where -1 means infinite.","solutions":["Pass 0 to disable the response timeout","Clamp the value: Math.max(0, responseTimeoutMs)","Correct the configuration or computation that produced the negative number"],"exampleFix":"// before\nbuilder.setResponseTimeoutMs(-5000);\n// after\nbuilder.setResponseTimeoutMs(Math.max(0, configuredTimeoutMs));","handlingStrategy":"validation","validationCode":"if (responseTimeoutMs < 0) throw new IllegalArgumentException(\"responseTimeoutMs must be >= 0, got \" + responseTimeoutMs);\nbuilder.setResponseTimeoutMs(Math.max(0, responseTimeoutMs));","typeGuard":null,"tryCatchPattern":"try {\n  builder.setResponseTimeoutMs(cfg.responseTimeoutMs());\n} catch (IllegalArgumentException e) {\n  log.warn(\"Bad response timeout, using default\", e);\n}","preventionTips":["Use 0 to disable the response timeout","Normalize values ported from other HTTP clients where -1 means infinite","Clamp any computed timeout before builder configuration"],"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"}