SonarSource/sonarqube · error · IllegalStateException

Fail to read response of

Error message

Fail to read response of 

What it means

IllegalStateException built by OkHttpResponse.fail when reading an OkHttp response body fails: content() wraps body.string() and if the underlying connection is interrupted, times out, or the body stream is otherwise unreadable, the IOException is rethrown as this error carrying the request URL. It is a transport/read failure on the client side, not an HTTP-level error status.

Solutions

  1. Check network stability / proxy behavior between client and SonarQube server
  2. Retry the request; the original request URL is included in the message
  3. Inspect the wrapped IOException cause for the root problem (timeout, reset, EOF)
  4. Read the body only once and close it properly to avoid double-read errors

Example fix

// before
String body = response.content(); // IllegalStateException on IO failure
// after
try {
  String body = response.content();
} catch (IllegalStateException e) {
  LOG.error("Failed reading response: {}", e.getMessage(), e.getCause());
  throw new RetryableWsException(e);
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  String body = response.content();
} catch (IllegalStateException e) {
  Throwable cause = e.getCause(); // original IOException
  throw new WsClientException("Response read failed: " + cause, e);
}

Prevention

When it happens

Trigger: Calling content()/contentReader() on an OkHttpResponse when the connection is broken mid-body, the stream was already consumed or closed, or the server reset the connection.

Common situations: Network drops during large response downloads, premature connection close by proxies, or reading the body of a response whose stream was already drained.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java:95

  @Override
  public Reader contentReader() {
    return okResponse.body().charStream();
  }

  /**
   * Get body content as a String. This response will be automatically closed.
   */
  @Override
  public String content() {
    try (ResponseBody body = okResponse.body()) {
      return body.string();
    } catch (IOException e) {
      throw fail(e);
    }
  }

  private RuntimeException fail(Exception e) {
    throw new IllegalStateException("Fail to read response of " + requestUrl(), e);
  }

  /**
   * Equivalent to closing contentReader or contentStream.
   */
  @Override
  public void close() {
    okResponse.close();
  }
}

View on GitHub (pinned to 184c821202)