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

dcapwell pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 202e673  Accord: NPE in RangeDeps.forEach
202e673 is described below

commit 202e67358396a1e413e29498bea71047bd586d06
Author: David Capwell <[email protected]>
AuthorDate: Wed May 1 09:08:47 2024 -0700

    Accord: NPE in RangeDeps.forEach
    
    patch by Benedict Elliott Smith, David Capwell; reviewed by Benedict 
Elliott Smith for CASSANDRA-19605
---
 accord-core/src/main/java/accord/primitives/RangeDeps.java  |  7 ++++++-
 .../src/test/java/accord/primitives/RangeDepsTest.java      | 13 +++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/accord-core/src/main/java/accord/primitives/RangeDeps.java 
b/accord-core/src/main/java/accord/primitives/RangeDeps.java
index 14c4bef..f939d26 100644
--- a/accord-core/src/main/java/accord/primitives/RangeDeps.java
+++ b/accord-core/src/main/java/accord/primitives/RangeDeps.java
@@ -149,6 +149,11 @@ public class RangeDeps implements 
Iterable<Map.Entry<Range, TxnId>>
         this.txnIdsToRanges = txnIdsToRanges;
     }
 
+    public void forEach(RoutableKey key, Consumer<TxnId> forEach)
+    {
+        forEach(key, Consumer::accept, forEach, 0, null);
+    }
+
     @Inline
     public <P1, P2, P3, P4> int forEach(RoutableKey key, 
IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, 
IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 
p4, int minIndex)
     {
@@ -270,7 +275,7 @@ public class RangeDeps implements Iterable<Map.Entry<Range, 
TxnId>>
      */
     public void forEach(Range range, Consumer<TxnId> forEach)
     {
-        forEach(range, forEach, 0, null);
+        forEach(range, Consumer::accept, forEach, 0, null);
     }
 
     /**
diff --git a/accord-core/src/test/java/accord/primitives/RangeDepsTest.java 
b/accord-core/src/test/java/accord/primitives/RangeDepsTest.java
index 2a41b22..bbb9356 100644
--- a/accord-core/src/test/java/accord/primitives/RangeDepsTest.java
+++ b/accord-core/src/test/java/accord/primitives/RangeDepsTest.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
 import java.util.*;
 
 import static accord.primitives.Txn.Kind.Write;
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class RangeDepsTest
 {
@@ -96,8 +97,12 @@ public class RangeDepsTest
 
         Set<TxnId> testOverlaps(Range range)
         {
+            List<TxnId> uniq = new ArrayList<>();
+            test.forEachUniqueTxnId(range, uniq::add);
             Set<TxnId> set = new TreeSet<>();
-            test.forEachUniqueTxnId(range, set::add);
+            test.forEach(range, set::add);
+            assertThat(uniq).doesNotHaveDuplicates()
+                            .containsExactlyInAnyOrderElementsOf(set);
             return set;
         }
 
@@ -114,8 +119,12 @@ public class RangeDepsTest
 
         Set<TxnId> testOverlaps(RoutableKey key)
         {
+            List<TxnId> uniq = new ArrayList<>();
+            test.forEachUniqueTxnId(key, uniq::add);
             Set<TxnId> set = new TreeSet<>();
-            test.forEachUniqueTxnId(key, set::add);
+            test.forEach(key, set::add);
+            assertThat(uniq).doesNotHaveDuplicates()
+                            .containsExactlyInAnyOrderElementsOf(set);
             return set;
         }
 


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

Reply via email to