Skip to content

Commit

Permalink
Merge pull request #39948 from quarkusio/IdentityOnClassloader
Browse files Browse the repository at this point in the history
Avoid identity hashcode on the production runtime classloader
  • Loading branch information
Sanne authored Apr 8, 2024
2 parents 79e2c51 + 6380301 commit e6e49ec
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 e6e49ec

Please sign in to comment.