Skip to content

Conversation

@zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Nov 27, 2025

Motivation and Context

Fix NPE issue thrown when using multipart S3 client to upload an object containing empty content without supplying a content length. Fix #6464

When uploading an empty object with unknown content length using the S3 multipart client, a NullPointerException was thrown because the code didn't handle the case
where no async request body chunks are received before the stream completes.

Modifications

• Modified UploadWithUnknownContentLengthHelper to handle empty streams by checking if any async request body has been received before onComplete() is called
• Added null check in onNext() to fail gracefully if a null async request body is passed
• Renamed isFirstAsyncRequestBody to firstAsyncRequestBodyReceived for better clarity
• When no request body is received, use AsyncRequestBody.empty() for single object upload

Testing

• Added new tests

Types of changes

• [x] Bug fix (non-breaking change which fixes an issue)
• [ ] New feature (non-breaking change which adds functionality)

Checklist

• [x] I have read the CONTRIBUTING document
• [x] Local run of mvn install succeeds
• [x] My code follows the code style of this project
• [ ] My change requires a change to the Javadoc documentation
• [ ] I have updated the Javadoc documentation accordingly
• [x] I have added tests to cover my changes
• [x] All new and existing tests passed
• [x] I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new
file created by the script in .changes/next-release with your changes.
• [ ] My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

• [x] I confirm that this pull request can be released under the Apache 2 license

…ct containing empty content without supplying a content length
@zoewangg zoewangg requested a review from a team as a code owner November 27, 2025 19:26
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE if s3AsyncClient.putObject is called with body containing empty content and unknown length

1 participant