[ 
https://issues.apache.org/jira/browse/WW-5546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17950143#comment-17950143
 ] 

Jesus M commented on WW-5546:
-----------------------------

We detect another issue with File Upload{*}{*}

*Title:*
File parameters in OGNL-mapped VO fail to bind during multipart requests

When submitting a multipart form (both via traditional form post and AJAX) to a 
Struts 2.7.0.3 action, simple type parameters (String, int, boolean) are 
properly bound to the Value Object (VO) through OGNL, but File type parameters 
consistently remain null.

*Environment:*
 * Struts 2.7.0.3

 * Standard fileUpload interceptor

 * Content-Type: multipart/form-data

 * Both form submit and AJAX implementations tested

*Steps to Reproduce:*
 # Define a VO with mixed parameter types:

 
 public class UploadVO { private File document; // Fails to bind private File 
attachment; // Fails to bind  private String title; // Binds correctly private 
int count; // Binds correctly // Standard getters/setters } # Create a 
multipart form:

 
 <form action="uploadAction" method="post" enctype="multipart/form-data"> 
<input type="file" name="document"> <input type="file" name="attachment"> 
<input type="text" name="title"> <input type="number" name="count"> </form> # 
Submit the form with all fields populated

*Expected Behavior:*
All parameters including File types should be properly bound to the VO through 
OGNL

*Actual Behavior:*
 * Simple types (title, count) are correctly bound

 * File type parameters (document, attachment) remain null

 * No errors or warnings are logged

 * HTTP 200 response is received

*Evidence of Defect:*
 # Verified against official documentation for file uploads

 # Tested multiple implementations (traditional form and AJAX)

 # Confirmed proper Content-Type header

 # Verified parameter names match VO property names

 # Confirmed setters are properly implemented

 # Tested with both default and explicit interceptor configurations

*Additional Notes:*
 * Issue occurs with both single and multiple file uploads

 * No difference between different file types/sizes

 * No stack traces or error messages generated

 * Workarounds using UploadedFile type also fail

 * Issue appears specific to OGNL binding of File types in VOs

*Suggested Priority:*
Major (blocks core file upload functionality)

*Attachments:*
(Would include sample project demonstrating the issue if available)

 

Why does this happen?

> 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: 1.5h
>  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)

Reply via email to