Skip to content

Commit

Permalink
HTTP2: Fix hashCode() and equals(...) implementation
Browse files Browse the repository at this point in the history
Motivation:

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

Modifications:

Correctly implement both methods

Result:

Fixes #13659
  • Loading branch information
normanmaurer committed Mar 12, 2024
1 parent a09cc16 commit b0bf6a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}
}

0 comments on commit b0bf6a0

Please sign in to comment.