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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -52,7 +52,7 @@ public boolean equals(Object o) {
public int hashCode() {
Http2FrameStream stream = this.stream;
if (stream == null) {
return super.hashCode();
return 31;
}
return stream.hashCode();
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
int hash = super.hashCode();
int hash = (int) (content ^ (content >>> 32));
hash = hash * 31 + (ack ? 1 : 0);
return hash;
}
Expand Down
Expand Up @@ -765,5 +765,28 @@ public State state() {
public String toString() {
return String.valueOf(id());
}

@Override
public int hashCode() {
Http2Stream stream = this.stream;
if (stream == null) {
return id;
}
return stream.hashCode();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
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);

}
}
}