SonarSource/sonarqube · error · IllegalArgumentException
Response timeout must be positive. Got
Error message
Response timeout must be positive. Got
What it means
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.
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
Example fix
// before builder.setResponseTimeoutMs(-5000); // after builder.setResponseTimeoutMs(Math.max(0, configuredTimeoutMs));
Defensive patterns
Strategy: validation
Validate before calling
if (responseTimeoutMs < 0) throw new IllegalArgumentException("responseTimeoutMs must be >= 0, got " + responseTimeoutMs);
builder.setResponseTimeoutMs(Math.max(0, responseTimeoutMs)); Try / catch
try {
builder.setResponseTimeoutMs(cfg.responseTimeoutMs());
} catch (IllegalArgumentException e) {
log.warn("Bad response timeout, using default", e);
} Prevention
- 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
When it happens
Trigger: Calling setResponseTimeoutMs with a negative long, e.g. a computed value or configuration constant that is negative; wired through HttpConnector's client preparation.
Common situations: 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.
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.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Connect timeout must be positive. Got
- Read timeout must be positive. Got
- Fail to request url:
- Address in property is not a valid address
- allowAllGroups can only be enabled when Auto-provisioning…
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/8ca89a1806159782.
Report an issue: GitHub.
Appendix: source
Thrown at sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java:184
/**
* Sets the default read timeout for new connections. A value of 0 means no timeout.
* Default is defined by OkHttp (10 seconds in OkHttp 3.3).
*/
public OkHttpClientBuilder setReadTimeoutMs(long l) {
if (l < 0) {
throw new IllegalArgumentException("Read timeout must be positive. Got " + l);
}
this.readTimeoutMs = l;
return this;
}
/**
* Sets the default response timeout for new connections. A value of 0 means no timeout.
* Default is to have no timeout.
*/
public OkHttpClientBuilder setResponseTimeoutMs(long l) {
if (l < 0) {
throw new IllegalArgumentException("Response timeout must be positive. Got " + l);
}
this.responseTimeoutMs = l;
return this;
}
/**
* Set if redirects should be followed or not.
* Default is defined by OkHttp (true, follow redirects).
*/
public OkHttpClientBuilder setFollowRedirects(Boolean followRedirects) {
this.followRedirects = followRedirects;
return this;
}
public OkHttpClient build() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.proxy(proxy);
if (connectTimeoutMs >= 0) {View on GitHub (pinned to 184c821202)