Skip to content

Commit

Permalink
Added null checks to avoid NPEs and addresses #213 (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam authored Sep 26, 2022
1 parent baa0328 commit 6ea4ae7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ public static <T> T finishResponse(HttpRequestor.Response response, ResponseHand
try {
return handler.handle(response);
} finally {
IOUtil.closeInput(response.getBody());
if (response != null) {
IOUtil.closeInput(response.getBody());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public void copyStreamToFile(InputStream in, File fout, int copyBufferSize) thro
*/
public static void closeInput(InputStream in) {
try {
in.close();
if (in != null) {
in.close();
}
} catch (IOException ex) {
// Ignore. We're done reading from it so we don't care if there are input errors.
}
Expand All @@ -137,7 +139,9 @@ public static void closeInput(InputStream in) {
*/
public static void closeInput(Reader in) {
try {
in.close();
if (in != null) {
in.close();
}
} catch (IOException ex) {
// Ignore. We're done reading from it so we don't care if there are input errors.
}
Expand Down

0 comments on commit 6ea4ae7

Please sign in to comment.