Skip to content

Commit

Permalink
Avoid identity hashcode on the production runtime classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Apr 8, 2024
1 parent 9fc4e97 commit 6380301
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,23 @@ public void beforeCheckpoint(Context<? extends Resource> ctx) {
public void afterRestore(Context<? extends Resource> ctx) {
}
}

@Override
public boolean equals(Object o) {
//see comment in hashCode
return this == o;
}

@Override
public int hashCode() {
//We can return a constant as we expect to have a single instance of these;
//this is useful to avoid triggering a call to the identity hashcode,
//which could be rather inefficient as there's good chances that some component
//will have inflated the monitor of this instance.
//A hash collision would be unfortunate but unexpected, and shouldn't be a problem
//as the equals implementation still does honour the identity contract .
//See also discussion on https://github.com/smallrye/smallrye-context-propagation/pull/443
return 1;
}

}

0 comments on commit 6380301

Please sign in to comment.