Skip to content

Commit 0369437

Browse files
committed
Explicit the null behavior
1 parent 18b4ba2 commit 0369437

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/Confluent.Kafka/Producer.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
770770
{
771771
Headers headers = message.Headers ?? new Headers();
772772

773-
ReadOnlyMemory<byte>? keyBytes = null;
773+
ReadOnlyMemory<byte>? keyBytes;
774774
try
775775
{
776776
if (keySerializer != null)
@@ -791,6 +791,10 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
791791
{
792792
keyBytes = readOnlyMemory;
793793
}
794+
else // Nullable Memory<byte>
795+
{
796+
keyBytes = null;
797+
}
794798
}
795799
catch (Exception ex)
796800
{
@@ -804,7 +808,7 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
804808
ex);
805809
}
806810

807-
ReadOnlyMemory<byte>? valBytes = null;
811+
ReadOnlyMemory<byte>? valBytes;
808812
try
809813
{
810814
if (valueSerializer != null)
@@ -825,6 +829,10 @@ public async Task<DeliveryResult<TKey, TValue>> ProduceAsync(
825829
{
826830
valBytes = readOnlyMemory;
827831
}
832+
else // Nullable Memory<byte>
833+
{
834+
valBytes = null;
835+
}
828836
}
829837
catch (Exception ex)
830838
{
@@ -923,7 +931,7 @@ public void Produce(
923931

924932
Headers headers = message.Headers ?? new Headers();
925933

926-
ReadOnlyMemory<byte>? keyBytes = null;
934+
ReadOnlyMemory<byte>? keyBytes;
927935
try
928936
{
929937
if (keySerializer != null)
@@ -943,6 +951,10 @@ public void Produce(
943951
{
944952
keyBytes = readOnlyMemory;
945953
}
954+
else // Nullable Memory<byte>
955+
{
956+
keyBytes = null;
957+
}
946958
}
947959
catch (Exception ex)
948960
{
@@ -956,7 +968,7 @@ public void Produce(
956968
ex);
957969
}
958970

959-
ReadOnlyMemory<byte>? valBytes = null;
971+
ReadOnlyMemory<byte>? valBytes;
960972
try
961973
{
962974
if (valueSerializer != null)
@@ -976,6 +988,10 @@ public void Produce(
976988
{
977989
valBytes = readOnlyMemory;
978990
}
991+
else // Nullable Memory<byte>
992+
{
993+
valBytes = null;
994+
}
979995
}
980996
catch (Exception ex)
981997
{

0 commit comments

Comments
 (0)