Skip to content

WW-5546 Fixes NPE when uploaded file is empty #1262

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

Open
wants to merge 1 commit into
base: release/struts-6-7-x
Choose a base branch
from

Conversation

lukaszlenart
Copy link
Member

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses WW-5546 by introducing a fix for a NullPointerException when an uploaded file is empty. Key changes include:

  • Adding a new static UploadedFile instance (NULL_CONTENT) in both FileUploadInterceptorTest and ActionFileUploadInterceptorTest.
  • Adding new tests (testAcceptFileWithNoContent) to validate the behavior when the uploaded file has no content.
  • Modifying AbstractFileUploadInterceptor to check for file content being null to avoid a NullPointerException.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java Added NULL_CONTENT constant and a test case for file with no content
core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java Added NULL_CONTENT constant and a test case for file with no content
core/src/main/java/org/apache/struts2/interceptor/AbstractFileUploadInterceptor.java Updated null-check to also consider file.getContent()
Comments suppressed due to low confidence (2)

core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java:256

  • [nitpick] Consider renaming the boolean variable 'notOk' to something clearer such as 'isRejected' to improve readability.
boolean notOk = interceptor.acceptFile(validation, NULL_CONTENT, "filename.html", "text/plain", "inputName");

core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java:259

  • [nitpick] Consider renaming the boolean variable 'notOk' to something clearer such as 'isRejected' for improved clarity in the test.
boolean notOk = interceptor.acceptFile(validation, NULL_CONTENT, "filename.html", "text/plain", "inputName");

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