diff --git a/src/contrib/cluster/Akka.DistributedData.Tests/LWWDictionarySpec.cs b/src/contrib/cluster/Akka.DistributedData.Tests/LWWDictionarySpec.cs
index 0b659512566..127cf7d96fa 100644
--- a/src/contrib/cluster/Akka.DistributedData.Tests/LWWDictionarySpec.cs
+++ b/src/contrib/cluster/Akka.DistributedData.Tests/LWWDictionarySpec.cs
@@ -161,5 +161,33 @@ public async Task Bugfix_4400_LWWDictionary_Deltas_must_merge_other_LWWDictionar
merged1.Entries["b"].Should().BeEquivalentTo("B2");
merged1.Entries["c"].Should().BeEquivalentTo("C");
}
+
+ ///
+ /// Bug reproduction: https://github.com/akkadotnet/akka.net/issues/7910
+ /// LWWDictionary.Delta should return null when underlying ORDictionary.Delta is null
+ ///
+ [Fact]
+ public void Bugfix_7910_LWWDictionary_Delta_should_handle_null_underlying_delta()
+ {
+ // Empty dictionary has no delta
+ var empty = LWWDictionary.Empty;
+ empty.Delta.Should().BeNull("empty dictionary should have null delta");
+
+ // After ResetDelta(), delta should be null
+ var m1 = LWWDictionary.Empty
+ .SetItem(_node1, "a", "A")
+ .SetItem(_node1, "b", "B");
+
+ m1.Delta.Should().NotBeNull("dictionary with modifications should have a delta");
+
+ var m2 = m1.ResetDelta();
+ m2.Delta.Should().BeNull("after ResetDelta(), delta should be null");
+
+ // Verify the dictionary still contains the data
+ m2.ContainsKey("a").Should().BeTrue();
+ m2.ContainsKey("b").Should().BeTrue();
+ m2["a"].Should().Be("A");
+ m2["b"].Should().Be("B");
+ }
}
}
diff --git a/src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs b/src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs
index 5562e88dd53..b556b7554ba 100644
--- a/src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs
+++ b/src/contrib/cluster/Akka.DistributedData/LWWDictionary.cs
@@ -402,8 +402,8 @@ public override int GetHashCode()
}
// TODO: optimize this so it doesn't allocate each time it's called
- public ORDictionary>.IDeltaOperation Delta =>
- new LWWDictionaryDelta(Underlying.Delta);
+ public ORDictionary>.IDeltaOperation Delta =>
+ Underlying.Delta == null ? null : new LWWDictionaryDelta(Underlying.Delta);
IReplicatedDelta IDeltaReplicatedData.Delta => Delta;