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

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit 1490fbf959fc0e7bc5d8be43250689ebf625942d
Author: aherbert <aherb...@apache.org>
AuthorDate: Thu Nov 21 14:16:03 2019 +0000

    [CODEC-269] Allow repeat calls to IncrementalHash32.end().
    
    Repeat calls with no additional data should create the same hash.
---
 src/changes/changes.xml                                           | 8 ++++++--
 src/main/java/org/apache/commons/codec/digest/MurmurHash3.java    | 8 +++++---
 .../java/org/apache/commons/codec/digest/MurmurHash3Test.java     | 1 +
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f57910c..1f3a2d1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -42,9 +42,13 @@ The <action> type attribute can be add,update,fix,remove.
   </properties>
   <body>
 
+    <release version="1.14" date="TBD" description="Feature and fix release.">
+      <action issue="CODEC-269" dev="aherbert" type="fix">Allow repeat calls 
to IncrementalHash32.end() to generate the same value.</action>
+    </release>
+
     <release version="1.13" date="2019-07-20" description="Feature and fix 
release.">
-      <action issue="CODEC-255" dev="sebb" due-to="Holger Grote" 
type="fix">ColognePhonetic handles x incorrectly</action>      
-      <action issue="CODEC-254" dev="sebb" due-to="Holger Grote" 
type="fix">ColognePhonetic does not treat the letter H correctly</action>      
+      <action issue="CODEC-255" dev="sebb" due-to="Holger Grote" 
type="fix">ColognePhonetic handles x incorrectly</action>
+      <action issue="CODEC-254" dev="sebb" due-to="Holger Grote" 
type="fix">ColognePhonetic does not treat the letter H correctly</action>
       <action issue="CODEC-134" dev="tmousaw-ptc" type="fix">Reject any decode 
request for a value that is impossible to encode to for Base32/Base64 rather 
than blindly decoding.</action>
       <action issue="CODEC-236" dev="melloware" due-to="Viliam Holub" 
type="add">MurmurHash2 for 32-bit or 64-bit value.</action>
       <action issue="CODEC-236" dev="melloware" due-to="Austin Appleby" 
type="add">MurmurHash3 for 32-bit or 128-bit value.</action>
diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java 
b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
index 95ab8b1..c7a149e 100644
--- a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
+++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
@@ -923,6 +923,8 @@ public final class MurmurHash3 {
          * @return The 32-bit hash
          */
         public final int end() {
+            // Allow calling end() again after adding no data to return the 
same result.
+            int result = hash;
             // ************
             // Note: This fails to apply masking using 0xff to the 3 remaining 
bytes.
             // ************
@@ -939,12 +941,12 @@ public final class MurmurHash3 {
                 k1 *= C1_32;
                 k1 = Integer.rotateLeft(k1, R1_32);
                 k1 *= C2_32;
-                hash ^= k1;
+                result ^= k1;
             }
 
             // finalization
-            hash ^= totalLen;
-            return fmix32(hash);
+            result ^= totalLen;
+            return fmix32(result);
         }
 
         /**
diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java 
b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
index a07dbb1..d7c21aa 100644
--- a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
@@ -597,6 +597,7 @@ public class MurmurHash3Test {
             offset += block;
             final int h2 = inc.end();
             Assert.assertEquals("Hashes differ", h1, h2);
+            Assert.assertEquals("Hashes differ after no additional data", h1, 
inc.end());
         }
     }
 }

Reply via email to