@@ -92,34 +92,41 @@ UpdateTaskImpl updateAab(@NonNull AppDistributionReleaseInternal newRelease) {
92
92
93
93
private String fetchDownloadRedirectUrl (String downloadUrl )
94
94
throws FirebaseAppDistributionException {
95
- HttpsURLConnection httpsURLConnection ;
95
+ HttpsURLConnection connection = null ;
96
96
int responseCode ;
97
+ String redirectUrl ;
97
98
98
99
try {
99
- httpsURLConnection = httpsUrlConnectionFactory .openConnection (downloadUrl );
100
- httpsURLConnection .setInstanceFollowRedirects (false );
101
- responseCode = httpsURLConnection .getResponseCode ();
100
+ connection = httpsUrlConnectionFactory .openConnection (downloadUrl );
101
+ connection .setInstanceFollowRedirects (false );
102
+ responseCode = connection .getResponseCode ();
103
+ redirectUrl = connection .getHeaderField ("Location" );
104
+ // Prevents a {@link LeakedClosableViolation} in strict mode even when the connection is
105
+ // disconnected
106
+ connection .getInputStream ().close ();
102
107
} catch (IOException e ) {
103
108
throw new FirebaseAppDistributionException (
104
109
"Failed to open connection to: " + downloadUrl , NETWORK_FAILURE , e );
110
+ } finally {
111
+ if (connection != null ) {
112
+ connection .disconnect ();
113
+ }
105
114
}
106
115
107
116
if (!isRedirectResponse (responseCode )) {
108
117
throw new FirebaseAppDistributionException (
109
118
"Expected redirect response code, but got: " + responseCode , DOWNLOAD_FAILURE );
110
119
}
111
- String redirect = httpsURLConnection .getHeaderField ("Location" );
112
- httpsURLConnection .disconnect ();
113
120
114
- if (redirect == null ) {
121
+ if (redirectUrl == null ) {
115
122
throw new FirebaseAppDistributionException (
116
123
"No Location header found in response from: " + downloadUrl , DOWNLOAD_FAILURE );
117
- } else if (redirect .isEmpty ()) {
124
+ } else if (redirectUrl .isEmpty ()) {
118
125
throw new FirebaseAppDistributionException (
119
126
"Empty Location header found in response from: " + downloadUrl , DOWNLOAD_FAILURE );
120
127
}
121
128
122
- return redirect ;
129
+ return redirectUrl ;
123
130
}
124
131
125
132
private static boolean isRedirectResponse (int responseCode ) {
0 commit comments