Skip to content

Commit

Permalink
Merge pull request #42282 from mkouba/issue-42271
Browse files Browse the repository at this point in the history
WebSockets Next: CloseReason - fix NPE if connection terminated abruptly
  • Loading branch information
gsmet authored Aug 2, 2024
2 parents 4f347e4 + 983b8bf commit 459ea4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public String getMessage() {
return message;
}

@Override
public String toString() {
return "CloseReason [code=" + code + ", " + (message != null ? "message=" + message : "") + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ public BroadcastSender broadcast() {
public CloseReason closeReason() {
WebSocketBase ws = webSocket();
if (ws.isClosed()) {
return new CloseReason(ws.closeStatusCode(), ws.closeReason());
Short code = ws.closeStatusCode();
if (code == null) {
// This could happen if the connection is terminated abruptly
return CloseReason.INTERNAL_SERVER_ERROR;
}
return new CloseReason(code, ws.closeReason());
}
return null;
}
Expand Down

0 comments on commit 459ea4e

Please sign in to comment.