Skip to content

Commit 9e47e0f

Browse files
authored
fix(okhttp): cannot call close if body is null
close: #7087 Signed-off-by: Steve Hawkins <[email protected]>
1 parent f356515 commit 9e47e0f

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Fix #7116: (java-generator) Use timezone format compatible with Kubernetes
55

66
#### Bugs
7+
* Fix #7087: Avoid possible NPE in OkHttp websocket handlinger
78
* Fix #7080: Avoid NPE in CRDGenerator if post-processor is set to null
89

910
#### Improvements

httpclient-okhttp/src/main/java/io/fabric8/kubernetes/client/okhttp/OkHttpWebSocketImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,10 @@ public static CompletableFuture<WebSocketResponse> buildAsync(OkHttpClient httpC
7575

7676
@Override
7777
public void onFailure(okhttp3.WebSocket webSocket, Throwable t, Response response) {
78-
if (response != null) {
79-
response.close();
80-
}
78+
// Ensure response body is always closed (leak)
79+
Optional.ofNullable(response).map(Response::body).ifPresent(ResponseBody::close);
8180
if (!opened) {
8281
if (response != null) {
83-
// Ensure response body is always closed (leak)
84-
Optional.ofNullable(response.body()).ifPresent(ResponseBody::close);
8582
final WebSocketUpgradeResponse upgradeResponse = new WebSocketUpgradeResponse(
8683
fabric8Request, response.code(), response.headers().toMultimap());
8784
future.complete(new WebSocketResponse(upgradeResponse, t));

0 commit comments

Comments
 (0)