-
Notifications
You must be signed in to change notification settings - Fork 475
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
SystemTextJson.DefaultLambdaJsonSerializer throws a NullReferenceException when null is returned if LAMBDA_NET_SERIALIZER_DEBUG is enabled #1328
Comments
@crose-varde Thanks for opening the bug report. Just out of curiosity, could you please share your use case where you needed to use Thanks, |
The issue is reproducible in actual AWS Lambda environment (not in Mock Lambda test tool), only when
@crose-varde Although I agree that the Thanks, |
@ashishdhingra consider this partial GraphQL schema:
The A direct lambda resolver that handles this will have to return |
Version 2.4.4 of Amazon.Lambda.Serialization.SystemTextJson has been released that fixes the debug null pointer exception. Thanks for letting us know. |
Comments on closed issues are hard for our team to see. |
Describe the bug
When using
Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer
(or any class derived fromAbstractLambdaJsonSerializer
), if theLAMBDA_NET_SERIALIZER_DEBUG
environment variable is set totrue
, andnull
is returned from the function handler, the debugging code invoked during serialization of the response causes aNullReferenceException
to be thrown.Expected Behavior
No exception should be thrown.
Current Behavior
If you're using
Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer
(or any class derived fromAmazon.Lambda.Serialization.SystemTextJson.AbstractLambdaJsonSerializer
) and you returnnull
from the function handler with theLAMBDA_NET_SERIALIZER_DEBUG
environment variable set totrue
you get this stack trace:Reproduction Steps
LAMBDA_NET_SERIALIZER_DEBUG
environment variable to true.Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer
for serialization:Possible Solution
The problem is in the serialization debugging code that is executed when
LAMBDA_NET_SERIALIZER_DEBUG
is set totrue
. The specific error is in AbstractLambdaJsonSerializer, when it tries to get the name of the response type to log to the console. When the response isnull
, thenresponse.GetType()
throws the NRE. If the debug flag isn't set, then this code path is never executed, and there's no exception.Additional Information/Context
Returning
null
is sometimes necessary when implementing an AppSync direct resolver, which is why I ran into this.AWS .NET SDK and/or Package version used
AWSSDK.Core 3.7.13.3
Amazon.Lambda.Core 2.1.0
Amazon.Lambda.Serialization.SystemTextJson 2.3.0
Targeted .NET Platform
.NET 6
Operating System and version
whatever lambda is running i guess (x86_64 arch)
The text was updated successfully, but these errors were encountered: