{"record":{"id":"7b23224c030aaf93","repo":"SonarSource/sonarqube","slug":"fail-to-read-response-of","errorCode":null,"errorMessage":"Fail to read response of ","messagePattern":"Fail to read response of ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java","lineNumber":95,"sourceCode":"  @Override\n  public Reader contentReader() {\n    return okResponse.body().charStream();\n  }\n\n  /**\n   * Get body content as a String. This response will be automatically closed.\n   */\n  @Override\n  public String content() {\n    try (ResponseBody body = okResponse.body()) {\n      return body.string();\n    } catch (IOException e) {\n      throw fail(e);\n    }\n  }\n\n  private RuntimeException fail(Exception e) {\n    throw new IllegalStateException(\"Fail to read response of \" + requestUrl(), e);\n  }\n\n  /**\n   * Equivalent to closing contentReader or contentStream.\n   */\n  @Override\n  public void close() {\n    okResponse.close();\n  }\n}\n","sourceCodeStart":77,"sourceCodeEnd":106,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java#L77-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"Network drops during large response downloads, premature connection close by proxies, or reading the body of a response whose stream was already drained.","solutions":["Check network stability / proxy behavior between client and SonarQube server","Retry the request; the original request URL is included in the message","Inspect the wrapped IOException cause for the root problem (timeout, reset, EOF)","Read the body only once and close it properly to avoid double-read errors"],"exampleFix":"// before\nString body = response.content(); // IllegalStateException on IO failure\n// after\ntry {\n  String body = response.content();\n} catch (IllegalStateException e) {\n  LOG.error(\"Failed reading response: {}\", e.getMessage(), e.getCause());\n  throw new RetryableWsException(e);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  String body = response.content();\n} catch (IllegalStateException e) {\n  Throwable cause = e.getCause(); // original IOException\n  throw new WsClientException(\"Response read failed: \" + cause, e);\n}","preventionTips":["Retry transient network failures on WS calls","Avoid reading a response body twice","Check proxy/timeout settings for large downloads","Close readers/streams in try-with-resources"],"tags":["http","io","response-body","network"],"backgroundTag":"http-request-failed","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"}