From 6e16ed9947865c82c273707575e2f62101900afe Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 12 Aug 2021 09:15:21 +0200 Subject: [PATCH] Close all ignored response bodies (#70) 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/ --- .../java/com/spotify/github/v3/clients/GitHubClient.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/spotify/github/v3/clients/GitHubClient.java b/src/main/java/com/spotify/github/v3/clients/GitHubClient.java index 2d4d9e92..d884b5e1 100644 --- a/src/main/java/com/spotify/github/v3/clients/GitHubClient.java +++ b/src/main/java/com/spotify/github/v3/clients/GitHubClient.java @@ -65,7 +65,11 @@ */ public class GitHubClient { - static final Consumer IGNORE_RESPONSE_CONSUMER = (ignore) -> {}; + static final Consumer IGNORE_RESPONSE_CONSUMER = (response) -> { + if (response.body() != null) { + response.body().close(); + } + }; static final TypeReference> LIST_COMMENT_TYPE_REFERENCE = new TypeReference<>() {}; static final TypeReference> LIST_REPOSITORY =