-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix possible NPE from WebSocketAdapter #7294
Conversation
Signed-off-by: Lachlan Roberts <[email protected]>
Do you want this in the 10.0.8 release? |
|
||
public RemoteEndpoint getRemote() | ||
{ | ||
return session.getRemote(); | ||
return remote; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO return session == null ? null : session.getRemote();
might be better. This is minor, but could save the remote
field. And I think the readability is not affected too much either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more surprising for getRemote()
to suddenly start returning null
after it was non-null.
Let the usage of Remote
trigger the exceptions indicating that you no longer have a valid connection/session/whatnot.
@@ -34,7 +35,8 @@ public Session getSession() | |||
|
|||
public boolean isConnected() | |||
{ | |||
return session.isOpen(); | |||
Session sess = this.session; | |||
return (sess != null) && (sess.isOpen()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just return session != null && session.isOpen();
should be more readable. Creating sess
here seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is standard multi threading coding practice.
The value of this.session
can actually change between the 2 evaluations (non-null check and isopen).
It could go from non-null to null between the two checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Thanks.
originally from PR #7293 by @azurvii
Fixes potential NPE from
WebSocketAdapter
if used beforeonWebSocketConnect()
is called.