Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSANDRA-19605: Fix NPE in RangeDeps.forEach #86

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion accord-core/src/main/java/accord/primitives/RangeDeps.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ private RangeDeps(Range[] ranges, TxnId[] txnIds, int[] rangesToTxnIds, int[] tx
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)
{
Expand Down Expand Up @@ -270,7 +275,7 @@ public <P1> void forEachUniqueTxnId(RoutableKey key, P1 p1, BiConsumer<P1, TxnId
*/
public void forEach(Range range, Consumer<TxnId> forEach)
{
forEach(range, forEach, 0, null);
forEach(range, Consumer::accept, forEach, 0, null);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions accord-core/src/test/java/accord/primitives/RangeDepsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.*;

import static accord.primitives.Txn.Kind.Write;
import static org.assertj.core.api.Assertions.assertThat;

public class RangeDepsTest
{
Expand Down Expand Up @@ -96,8 +97,12 @@ Set<TxnId> canonicalOverlaps(Range range)

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;
}

Expand All @@ -114,8 +119,12 @@ Set<TxnId> canonicalOverlaps(RoutableKey key)

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;
}

Expand Down