Skip to content

Commit 4f09695

Browse files
authored
Merge branch 'master' into string-comparison
2 parents a048c68 + 49a12eb commit 4f09695

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/com/sendgrid/Client.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ public class Client {
4949

5050
private CloseableHttpClient httpClient;
5151
private Boolean test;
52+
private boolean createdHttpClient;
5253

5354
/**
5455
* Constructor for using the default CloseableHttpClient.
5556
*/
5657
public Client() {
57-
this(false);
58+
this.httpClient = HttpClients.createDefault();
59+
this.test = false;
60+
this.createdHttpClient = true;
5861
}
5962

6063
/**
61-
* Constructor for passing in an httpClient.
64+
* Constructor for passing in an httpClient, typically for mocking. Passed-in httpClient will not be closed
65+
* by this Client.
6266
*
6367
* @param httpClient
6468
* an Apache CloseableHttpClient
@@ -88,6 +92,7 @@ public Client(Boolean test) {
8892
public Client(CloseableHttpClient httpClient, Boolean test) {
8993
this.httpClient = httpClient;
9094
this.test = test;
95+
this.createdHttpClient = true;
9196
}
9297

9398

@@ -340,7 +345,9 @@ public Response api(Request request) throws IOException {
340345
@Override
341346
public void finalize() throws Throwable {
342347
try {
343-
this.httpClient.close();
348+
if(this.createdHttpClient) {
349+
this.httpClient.close();
350+
}
344351
} catch(IOException e) {
345352
throw new Throwable(e.getMessage());
346353
} finally {

0 commit comments

Comments
 (0)