Skip to content

Commit caa13b4

Browse files
committed
Check for null stream before attempting to close
1 parent 0dd2e68 commit caa13b4

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/main/java/com/stackify/api/common/http/HttpClient.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ public String post(final String path, final byte[] jsonBytes, final boolean gzip
165165
/**
166166
* Reads all remaining contents from the stream and closes it
167167
* @param stream The stream
168-
* @return THe contents of the stream
168+
* @return The contents of the stream
169169
* @throws IOException
170170
*/
171171
private String readAndClose(final InputStream stream) throws IOException {
172-
Preconditions.checkNotNull(stream);
172+
String contents = null;
173173

174-
String contents = CharStreams.toString(new InputStreamReader(new BufferedInputStream(stream), "UTF-8"));
175-
stream.close();
174+
if (stream != null) {
175+
contents = CharStreams.toString(new InputStreamReader(new BufferedInputStream(stream), "UTF-8"));
176+
stream.close();
177+
}
176178

177179
return contents;
178180
}

0 commit comments

Comments
 (0)