Skip to content

SendMessageBatchResponse.Failed and Successful should be marked as nullable because they are #4200

@rianjs

Description

@rianjs

Describe the bug

The comment even says it can be nullable in v4+, but the List isn't marked with a ?, and because it's lazy, this results in NullReferenceExceptions that the compiler doesn't catch, even when <Nullable>enable</Nullable>.

public partial class SendMessageBatchResponse : AmazonWebServiceResponse
{
    private List<BatchResultErrorEntry> _failed = AWSConfigs.InitializeCollections ? new List<BatchResultErrorEntry>() : null;
    private List<SendMessageBatchResultEntry> _successful = AWSConfigs.InitializeCollections ? new List<SendMessageBatchResultEntry>() : null;

    /// <summary>
    /// Gets and sets the property Failed. 
    /// <para>
    /// A list of <c> <a>BatchResultErrorEntry</a> </c> items with error details about each
    /// message that can't be enqueued.
    /// </para>
    /// <para />
    /// Starting with version 4 of the SDK this property will default to null. If no data for this property is returned
    /// from the service the property will also be null. This was changed to improve performance and allow the SDK and caller
    /// to distinguish between a property not set or a property being empty to clear out a value. To retain the previous
    /// SDK behavior set the AWSConfigs.InitializeCollections static property to true.
    /// </summary>
    [AWSProperty(Required=true)]
    public List<BatchResultErrorEntry> Failed
    {
        get { return this._failed; }
        set { this._failed = value; }
    }

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

One of two things:

_log.LogInformation($"<snip> failures: {sendResult.Failed.Count}");

This code should either be safe like it is in v3, OR the compiler should tell me I've got a problem, but because there's no ? on Failed, we don't get the null safety.

Current Behavior

We got an NRE.

Reproduction Steps

  1. Instantiate the response object. Leave the backing collection for Failed as null.
  2. Reference Failed
  3. Reference Successful

The compiler won't warn you, and both will trigger NREs.

Possible Solution

Mark the properties with ?

Have your LLM look for similar traps in the rest of the library while you're at it.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Targeted .NET Platform

.NET 10

Operating System and version

macOS Tahoe 26.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-reviewpotential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions