Skip to content
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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jmsusanto
Copy link
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.

@@ -37,7 +37,8 @@ public ParsedMessage(final Message message, final boolean failedParsing) {
// S3EventNotification contains only one S3EventNotificationRecord
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
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
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 <[email protected]>
Copy link
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
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
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
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.

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