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

fix(taskAttachment): prevent NPE for deletion of attachments with empty or nonexisting taskId #4817

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

PHWaechtler
Copy link
Contributor

@PHWaechtler PHWaechtler commented Nov 27, 2024

related to #3545

  • adds checks for empty or nonExistent taskIds when deleting a taskAttachment

Behaviour is now:
Deleting a task attachment providing an empty taskID:

  • it will try to find the attachment via attachmentId. If no attachment found, exception is returned stating no attachment exists
  • if an attachment with the given attachmentId exists, it will delete this attachment.
  • no attempt is made to update the nonexisting task, avoiding the NPE

Deleting a task attachment with an ID of a task that has already been completed:

  • if the attachment still exists, the attachment will be deleted
  • no attempt is made to update the nonexisting task, avoiding the NPE

Note:
Due to this existing implementation, the NullValueException thrown in the Delete command will always be returned as an InvalidRequestException as the API response. I am assuming this is expected behaviour, but lmk if that should be adjusted in any way.

@PHWaechtler PHWaechtler force-pushed the 3545-npe-thrown-during-deletion-of-attachment branch from 9a89b08 to cd73812 Compare November 27, 2024 12:43
engine/pom.xml Outdated Show resolved Hide resolved
@PHWaechtler PHWaechtler force-pushed the 3545-npe-thrown-during-deletion-of-attachment branch 2 times, most recently from 3859a8a to 997d9a0 Compare November 27, 2024 13:08
Comment on lines +2242 to +2243
Attachment attachment = taskService.createAttachment("web page", "", null, "weatherforcast",
"temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
Copy link
Contributor Author

@PHWaechtler PHWaechtler Nov 27, 2024

Choose a reason for hiding this comment

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

Suggested follow up:
Based on my understanding of the issue, I think it would also make sense to look into prohibiting the creation of attachments with empty taskId and null (or empty) processInstanceId. At the moment, this is still allowed because the creation only checks for the taskId not being null. I can open a follow up ticket if you agree that this makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

So basically without your fix, we can create a taskless attachment but not delete it, but with your changes, we'll be able to do both, is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, but its more about creating an attachment without taskId and without processInstanceId. My understanding is that it should have either one or the other, but that its fine for it to not have a taskId as long as it still has a processInstanceId.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joaquinfelici can you let me know about whether to open a follow up for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

From what we can see in the create attachment documentation, what you say makes sense.

@param processInstanceId - id of a process to use if task id is null

I guess we can create a follow-up ticket to prevent that both taskId and processInstanceId are null on creation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the follow up ticket

@PHWaechtler PHWaechtler force-pushed the 3545-npe-thrown-during-deletion-of-attachment branch 3 times, most recently from 7194bf2 to 00965bc Compare November 28, 2024 11:16
@PHWaechtler PHWaechtler force-pushed the 3545-npe-thrown-during-deletion-of-attachment branch from 00965bc to a42a645 Compare November 28, 2024 11:27
@PHWaechtler PHWaechtler requested a review from tasso94 November 28, 2024 12:35
@PHWaechtler PHWaechtler self-assigned this Nov 28, 2024
@PHWaechtler PHWaechtler requested review from joaquinfelici and removed request for tasso94 November 28, 2024 13:13
Copy link
Contributor

@joaquinfelici joaquinfelici left a comment

Choose a reason for hiding this comment

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

Look good! Added some question for clarification and minor suggestions.

engine/pom.xml Outdated Show resolved Hide resolved
Comment on lines +2242 to +2243
Attachment attachment = taskService.createAttachment("web page", "", null, "weatherforcast",
"temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
Copy link
Contributor

Choose a reason for hiding this comment

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

So basically without your fix, we can create a taskless attachment but not delete it, but with your changes, we'll be able to do both, is that correct?

@PHWaechtler PHWaechtler merged commit 7e974cf into master Dec 4, 2024
4 checks passed
@PHWaechtler PHWaechtler deleted the 3545-npe-thrown-during-deletion-of-attachment branch December 4, 2024 14:24
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.

2 participants