Close input stream when fetching new releases
@@ -105,7 +105,8 @@ class FirebaseAppDistributionTesterApiClient {
private String readResponseBody(HttpsURLConnection connection) throws IOException {
boolean isSuccess = isResponseSuccess(connection.getResponseCode());
- InputStream inputStream = isSuccess ? connection.getInputStream() : connection.getErrorStream();
+ try (InputStream inputStream =
+ isSuccess ? connection.getInputStream() : connection.getErrorStream()) {
if (inputStream == null && !isSuccess) {
// If the server returns a response with an error code and no response body, getErrorStream
// returns null. We return an empty string to reflect the empty body.
@@ -113,6 +114,7 @@ class FirebaseAppDistributionTesterApiClient {
}
return convertInputStreamToString(new BufferedInputStream(inputStream));
}
+ }
private static boolean isResponseSuccess(int responseCode) {
return responseCode >= 200 && responseCode < 300;
