This is an automated email from the ASF dual-hosted git repository.

tabish121 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new 26d64220 PROTON-2947 Fix return value of cached hashCode calculation 
in Binary
26d64220 is described below

commit 26d64220f60cc538c5209a9fb4930c9a8ea17969
Author: Arnaud Cogoluègnes <[email protected]>
AuthorDate: Wed Aug 5 11:05:45 2026 +0200

    PROTON-2947 Fix return value of cached hashCode calculation in Binary
    
    The hashCode() method was returning the local hc variable
    (which initialized to 0) on the first invocation, rather than the newly
    computed hash code. This caused inconsistent hash values across calls
    on the same instance, leading to Map lookup failures when iterating or
    copying maps across different JDK versions.
---
 protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java
index 0aac1340..f764c8fb 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java
@@ -124,7 +124,8 @@ public final class Binary {
     public final int hashCode() {
         int hc = hashCode;
         if (hc == 0 && buffer != null) {
-            hashCode = buffer.hashCode();
+            hc = buffer.hashCode();
+            hashCode = hc;
         }
         return hc;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to