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

HTTP2: Fix hashCode() and equals(...) implementation #13903

Open
wants to merge 1 commit into
base: 4.1
Choose a base branch
from

Conversation

normanmaurer
Copy link
Member

Motivation:

Our implementations of hashCode() and equals(...) were not correct for some frames.

Modifications:

Correctly implement both methods

Result:

Fixes #13659

Motivation:

Our implementations of hashCode() and equals(...) were not correct for some frames.

Modifications:

Correctly implement both methods

Result:

Fixes #13659
Copy link
Contributor

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

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

In general, I worry about properly implementing hashCode() for objects with mutable state since it can lead to hash table corruption. The risk feels more pronounced in DefaultHttp2FrameStream as its fields are volatile and set in couple different places.

Is that the intended use case of these methods? Most of them don't feel like good candidates for keys in a map/set as it is. .equals(..) is more valuable especially for tests. If that's the primary use case we could go with naive hashCode methods despite the high probability of collision.

DefaultHttp2FrameStream that = (DefaultHttp2FrameStream) o;
Http2Stream stream = this.stream;
Http2Stream thatStream = that.stream;
return id == that.id && stream != null && stream.equals(thatStream);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are two DefaultHttp2FrameStream considered equal if this.stream == that.stream == null?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say yes, but it's a good point @bryce-anderson (maybe I'm wrong!)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they'd be considered equal as well, although I don't believe it's covered by this implementation.
This would probably do it:

return this.id == that.id && Objects.equals(this.stream, that.stream);

@franz1981
Copy link
Contributor

How did you discovered @normanmaurer ?

@normanmaurer
Copy link
Member Author

@franz1981 someone else did #13659

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.

AbstractHttp2StreamFrame and DefaultHttp2PingFrame hashCode seems incorrect
3 participants