[
https://issues.apache.org/jira/browse/WW-5546?focusedWorklogId=968618&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-968618
]
ASF GitHub Bot logged work on WW-5546:
--------------------------------------
Author: ASF GitHub Bot
Created on: 06/May/25 10:11
Start Date: 06/May/25 10:11
Worklog Time Spent: 10m
Work Description: lukaszlenart commented on code in PR #1262:
URL: https://github.com/apache/struts/pull/1262#discussion_r2075154964
##########
core/src/test/java/org/apache/struts2/interceptor/ActionFileUploadInterceptorTest.java:
##########
@@ -205,6 +252,22 @@ public void testAcceptFileWithNoFile() {
assertTrue(msg.indexOf("inputName") > 0);
}
+ public void testAcceptFileWithNoContent() {
+ interceptor.setAllowedTypes("text/plain");
+
+ ValidationAwareSupport validation = new ValidationAwareSupport();
+ boolean notOk = interceptor.acceptFile(validation, NULL_CONTENT,
"filename.html", "text/plain", "inputName");
+
+ assertFalse(notOk);
+ assertFalse(validation.getFieldErrors().isEmpty());
+ assertTrue(validation.hasErrors());
+ List<String> errors = validation.getFieldErrors().get("inputName");
Review Comment:
I want to make this change as small as possible, I will do a large
refactoring once cherry-picking changes into Struts 7
Issue Time Tracking
-------------------
Worklog Id: (was: 968618)
Time Spent: 40m (was: 0.5h)
> NPE in AbstractFileUploadInterceptor
> ------------------------------------
>
> Key: WW-5546
> URL: https://issues.apache.org/jira/browse/WW-5546
> Project: Struts 2
> Issue Type: Bug
> Components: Core, Core Interceptors
> Affects Versions: 6.7.4
> Reporter: Barta Tamás
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 6.8.0, 7.1.0
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> I got the following exception:
>
> {code:java}
> java.lang.NullPointerException: Cannot invoke "java.io.File.length()" because
> "this.file" is null
> at
> deployment.deployment.ear//org.apache.struts2.dispatcher.multipart.StrutsUploadedFile.length(StrutsUploadedFile.java:52)
> at
> deployment.deployment.ear//org.apache.struts2.interceptor.AbstractFileUploadInterceptor.acceptFile(AbstractFileUploadInterceptor.java:133)
> at
> deployment.deployment.ear//org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:232)
> at
> deployment.deployment.ear//com.opensymphony.xwork2.interceptor.AbstractInterceptor.intercept(AbstractInterceptor.java:36)
> at
> deployment.deployment.ear//com.opensymphony.xwork2.DefaultActionInvocation.executeConditional(DefaultActionInvocation.java:303)
> {code}
> I think the bug is in AbstractFileUploadInterceptor:
>
>
> {code:java}
> if (file.getContent() == null) {
> String errMsg = getTextMessage(action,
> STRUTS_MESSAGES_ERROR_UPLOADING_KEY, new String[]{originalFilename});
>
> errorMessages.add(errMsg);
> LOG.warn(errMsg);
> }
> if (maximumSize != null && maximumSize < file.length()) { {code}
> If file.getContent() is null (which means StrutsUploadedFile.file is null),
> then warning is logged but there is no "return false" so execution continues
> and file.length() will throw NPE as file is null in StrutsUploadedFile.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)