From 3e8504c79e13050af39796a09b23a0d66518add0 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Sat, 9 Dec 2023 14:17:30 -0800 Subject: [PATCH] Nullability: verify ReferenceCount(null) GetHashCode (#539) --- BitFaster.Caching.UnitTests/ReferenceCountTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BitFaster.Caching.UnitTests/ReferenceCountTests.cs b/BitFaster.Caching.UnitTests/ReferenceCountTests.cs index 7824b657..429d2001 100644 --- a/BitFaster.Caching.UnitTests/ReferenceCountTests.cs +++ b/BitFaster.Caching.UnitTests/ReferenceCountTests.cs @@ -58,5 +58,15 @@ public void WhenObjectsAreDifferentHashcodesAreDifferent() a.GetHashCode().Should().NotBe(b.GetHashCode()); } + + [Fact] + public void WhenObjectIsNullGetHashCodeDoesntThrow() + { + var a = new ReferenceCount(null); + + // nullable static analysis suggests this is broken, but it is legal to call + // EqualityComparer.Default.GetHashCode(null) + a.GetHashCode(); + } } }