8000 Swallow exception from close call when there is an underlying IOExcep… · monical1/google-http-java-client@75c2b20 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75c2b20

Browse files
chajathejona86
authored andcommitted
Swallow exception from close call when there is an underlying IOException
1 parent 49da636 commit 75c2b20

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

google-http-client/src/main/java/com/google/api/client/http/javanet/NetHttpRequest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,21 @@ public LowLevelHttpResponse execute() throws IOException {
7575
connection.setChunkedStreamingMode(0);
7676
}
7777
OutputStream out = connection.getOutputStream();
78+
boolean threw = true;
7879
try {
7980
getStreamingContent().writeTo(out);
81+
threw = false;
8082
} finally {
81-
out.close();
83+
try {
84+
out.close();
85+
} catch (IOException exception) {
86+
// When writeTo() throws an exception, chances are that the close call will also fail.
87+
// In such case, swallow exception from close call so that the underlying cause can
88+
// propagate.
89+
if (!threw) {
90+
throw exception;
91+
}
92+
}
8293
}
8394
} else {
8495
// cannot call setDoOutput(true) because it would change a GET method to POST

0 commit comments

Comments
 (0)
0