Skip to content

S3-Source Bug Fix: Handle null object size for non S3-Create Events#5449

Merged
graytaylor0 merged 2 commits intoopensearch-project:mainfrom
jmsusanto:S3BugFix
Feb 26, 2025
Merged

S3-Source Bug Fix: Handle null object size for non S3-Create Events#5449
graytaylor0 merged 2 commits intoopensearch-project:mainfrom
jmsusanto:S3BugFix

Conversation

@jmsusanto
Copy link
Copy Markdown
Contributor

Description

This PR fixes a NullPointerException that occurs when processing non S3-create events such as S3-delete due to the absence of an object size in the event notification. The getSizeAsLong() method can return null for delete events, which caused the application to throw an error.

Issues Resolved

Resolves #5448

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Jeremy Michael <jsusanto@amazon.com>
this.bucketName = notificationRecords.get(0).getS3().getBucket().getName();
this.objectKey = notificationRecords.get(0).getS3().getObject().getUrlDecodedKey();
this.objectSize = notificationRecords.get(0).getS3().getObject().getSizeAsLong();
Long size = notificationRecords.get(0).getS3().getObject().getSizeAsLong();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a unit test

Signed-off-by: Jeremy Michael <jsusanto@amazon.com>
Copy link
Copy Markdown
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought we had code that filtered out the events so that only created events were processed.

@jmsusanto
Copy link
Copy Markdown
Contributor Author

jmsusanto commented Feb 20, 2025

I actually thought we had code that filtered out the events so that only created events were processed.

@dlvenable The issue is that we're calling final Collection<ParsedMessage> s3MessageEventNotificationRecords = sqsMessageParser.parseSqsMessages(sqsMessages); before the code that handles non-create events. The code that you're referencing acts on the ParsedMessages, but the error occurs when we create these ParsedMessages, so we never get there.

@graytaylor0
Copy link
Copy Markdown
Member

Were you able to confirm that with this change a DeleteEvent did not hit an error and the SQS message for it was deleted?

@jmsusanto
Copy link
Copy Markdown
Contributor Author

Were you able to confirm that with this change a DeleteEvent did not hit an error and the SQS message for it was deleted?

@graytaylor0 After this change, we don't hit an error and DeleteEvent messages get deleted. The issue was primarily during the creation of the ParsedMessages.

@graytaylor0 graytaylor0 merged commit 837d1a9 into opensearch-project:main Feb 26, 2025
45 of 47 checks passed
divbok pushed a commit to divbok/data-prepper that referenced this pull request Mar 4, 2025
chenqi0805 pushed a commit to chenqi0805/data-prepper that referenced this pull request Apr 2, 2025
…pensearch-project#5449)

Signed-off-by: Jeremy Michael <jsusanto@amazon.com>
Signed-off-by: George Chen <qchea@amazon.com>
amdhing pushed a commit to amdhing/data-prepper that referenced this pull request Apr 16, 2025
Davidding4718 pushed a commit to Davidding4718/data-prepper that referenced this pull request Apr 25, 2025
Davidding4718 pushed a commit to Davidding4718/data-prepper that referenced this pull request Apr 25, 2025
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.

[BUG] NullPointerException on S3 Delete Event Due to Null Object Size

4 participants