File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
src/main/java/com/microsoft/graph/http Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ public Request authenticateRequest(Request request) {
269269 .tag (RetryOptions .class , retryOptions );
270270
271271 String contenttype = null ;
272+ Response response = null ;
272273
273274 try {
274275 logger .logDebug ("Request Method " + request .getHttpMethod ().toString ());
@@ -353,7 +354,7 @@ public MediaType contentType() {
353354 coreHttpRequest = corehttpRequestBuilder .build ();
354355
355356 // Call being executed
356- Response response = corehttpClient .newCall (coreHttpRequest ).execute ();
357+ response = corehttpClient .newCall (coreHttpRequest ).execute ();
357358
358359 if (handler != null ) {
359360 handler .configConnection (response );
@@ -401,12 +402,13 @@ public MediaType contentType() {
401402 return (Result ) handleBinaryStream (in );
402403 }
403404 } finally {
404- if (!isBinaryStreamInput && in != null ) {
405+ if (!isBinaryStreamInput ) {
405406 try {
406- in .close ();
407+ if ( in != null ) in .close ();
407408 }catch (IOException e ) {
408409 logger .logError (e .getMessage (), e );
409410 }
411+ if (response != null ) response .close ();
410412 }
411413 }
412414 } catch (final GraphServiceException ex ) {
Original file line number Diff line number Diff line change 2323package com .microsoft .graph .http ;
2424
2525import java .io .IOException ;
26+ import java .io .InputStream ;
2627import java .util .LinkedList ;
2728import java .util .List ;
2829import java .util .Locale ;
3839import com .microsoft .graph .serializer .ISerializer ;
3940
4041import okhttp3 .Response ;
42+ import static okhttp3 .internal .Util .closeQuietly ;
4143
4244/**
4345 * An exception from the Graph service
@@ -416,8 +418,12 @@ public static <T> GraphServiceException createFromConnection(final IHttpRequest
416418
417419 final String responseMessage = response .message ();
418420 String rawOutput = "{}" ;
419- if (response .body ().byteStream () != null ) {
420- rawOutput = DefaultHttpProvider .streamToString (response .body ().byteStream ());
421+
422+ InputStream is = response .body ().byteStream ();
423+ try {
424+ rawOutput = DefaultHttpProvider .streamToString (is );
425+ } finally {
426+ closeQuietly (is );
421427 }
422428 GraphErrorResponse error ;
423429 try {
You can’t perform that action at this time.
0 commit comments