Skip to content
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

Merged
merged 1 commit into from
Dec 16, 2021

Conversation

lachlan-roberts
Copy link
Contributor

originally from PR #7293 by @azurvii

Fixes potential NPE from WebSocketAdapter if used before onWebSocketConnect() is called.

@joakime
Copy link
Contributor

joakime commented Dec 16, 2021

Do you want this in the 10.0.8 release?


public RemoteEndpoint getRemote()
{
return session.getRemote();
return remote;
Copy link

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.

Copy link
Contributor

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());
Copy link

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.

Copy link
Contributor

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Thanks.

@lachlan-roberts lachlan-roberts merged commit 80b15ce into jetty-10.0.x Dec 16, 2021
@lachlan-roberts lachlan-roberts deleted the jetty-10.0.x-7293-WS_NPE branch December 16, 2021 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants