Fix NPE issue in multipart S3 client #6594
Open
+114
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



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