From 6380301cde674087f12cc570bbab12efedd23f6e Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 8 Apr 2024 14:50:21 +0100 Subject: [PATCH] Avoid identity hashcode on the production runtime classloader --- .../bootstrap/runner/RunnerClassLoader.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java index f0047050d8d62..3e528969e5899 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java @@ -316,4 +316,23 @@ public void beforeCheckpoint(Context ctx) { public void afterRestore(Context 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; + } + }