Skip to content

Commit

Permalink
Close all ignored response bodies (#70)
Browse files Browse the repository at this point in the history
This fixes several warnings of this form (#65):
A connection to https://github.com/ was leaked. Did you forget to close a response body?

According to the okhttp documentation:
"Response bodies must be closed and may be consumed only once"
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-response/body/
  • Loading branch information
thna123459 authored Aug 12, 2021
1 parent db9e609 commit 6e16ed9
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
*/
public class GitHubClient {

static final Consumer<Response> IGNORE_RESPONSE_CONSUMER = (ignore) -> {};
static final Consumer<Response> IGNORE_RESPONSE_CONSUMER = (response) -> {
if (response.body() != null) {
response.body().close();
}
};
static final TypeReference<List<Comment>> LIST_COMMENT_TYPE_REFERENCE =
new TypeReference<>() {};
static final TypeReference<List<Repository>> LIST_REPOSITORY =
Expand Down

0 comments on commit 6e16ed9

Please sign in to comment.