From 02eb5b4553279144392ae3288f9fdd5279073277 Mon Sep 17 00:00:00 2001 From: Norm Johanson Date: Sun, 20 Oct 2024 15:02:24 -0700 Subject: [PATCH] Add null checks before attempting debug response writing --- .../src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs | 2 +- .../AbstractLambdaJsonSerializer.cs | 2 +- .../LambdaJsonSerializer.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs b/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs index 77c23e1e6..0555e2f9c 100644 --- a/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs +++ b/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs @@ -94,7 +94,7 @@ public void Serialize(T response, Stream responseStream) { try { - if (debug) + if (debug && response != null) { using (StringWriter debugWriter = new StringWriter()) { diff --git a/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/AbstractLambdaJsonSerializer.cs b/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/AbstractLambdaJsonSerializer.cs index 0f27cf3fa..2656c535b 100644 --- a/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/AbstractLambdaJsonSerializer.cs +++ b/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/AbstractLambdaJsonSerializer.cs @@ -48,7 +48,7 @@ public void Serialize(T response, Stream responseStream) { try { - if (_debug) + if (_debug && response != null) { using (var debugStream = new MemoryStream()) using (var utf8Writer = new Utf8JsonWriter(debugStream, WriterOptions)) diff --git a/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/LambdaJsonSerializer.cs b/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/LambdaJsonSerializer.cs index bc162f227..dae777b54 100644 --- a/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/LambdaJsonSerializer.cs +++ b/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/LambdaJsonSerializer.cs @@ -95,7 +95,7 @@ public void Serialize(T response, Stream responseStream) { try { - if (_debug) + if (_debug && response != null) { using (var debugWriter = new StringWriter()) using (var utf8Writer = new Utf8JsonWriter(responseStream, WriterOptions))