Author: niallp
Date: Tue Dec 16 13:53:05 2008
New Revision: 727179

URL: http://svn.apache.org/viewvc?rev=727179&view=rev
Log:
Fix (and test) for STR-3173 NullPointerException in 
org.apache.struts.util.RequestUtils.rationalizeMultipleFileProperty - reported 
by Xavier Poinsard

Added:
    
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp
   (contents, props changed)
      - copied, changed from r727129, 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload.jsp
Modified:
    
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/java/org/apache/struts/webapp/upload/UploadAction.java
    
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/WEB-INF/upload/struts-config.xml
    
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/welcome.jsp
    
struts/struts1/branches/STRUTS_1_3_BRANCH/core/src/main/java/org/apache/struts/util/RequestUtils.java

Modified: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/java/org/apache/struts/webapp/upload/UploadAction.java
URL: 
http://svn.apache.org/viewvc/struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/java/org/apache/struts/webapp/upload/UploadAction.java?rev=727179&r1=727178&r2=727179&view=diff
==============================================================================
--- 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/java/org/apache/struts/webapp/upload/UploadAction.java
 (original)
+++ 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/java/org/apache/struts/webapp/upload/UploadAction.java
 Tue Dec 16 13:53:05 2008
@@ -79,6 +79,11 @@
             //retrieve the file representation
             FormFile file = theForm.getTheFile();
 
+            // Following is to test fix for STR-3173
+            if (file == null) {
+                file = 
(FormFile)form.getMultipartRequestHandler().getFileElements().get("otherFile");
+            }
+
             //retrieve the file name
             String fileName= file.getFileName();
 

Modified: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/WEB-INF/upload/struts-config.xml
URL: 
http://svn.apache.org/viewvc/struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/WEB-INF/upload/struts-config.xml?rev=727179&r1=727178&r2=727179&view=diff
==============================================================================
--- 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/WEB-INF/upload/struts-config.xml
 (original)
+++ 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/WEB-INF/upload/struts-config.xml
 Tue Dec 16 13:53:05 2008
@@ -38,6 +38,20 @@
             <forward name="display" path="/display.jsp"/>
         </action>
 
+
+        <!-- Upload Actions to test Bug# STR-3173 -->
+        <action path="/upload2" forward="/upload2.jsp"/>
+
+        <action path="/upload-submit2"
+                type="org.apache.struts.webapp.upload.UploadAction"
+                name="uploadForm"
+                scope="request"
+                validate="true"
+                input="input">
+            <forward name="input" path="/upload2.jsp"/>
+            <forward name="display" path="/display.jsp"/>
+        </action>
+
     </action-mappings>
 
     <!-- This is where you set the maximum file size for your file uploads.

Copied: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp
 (from r727129, 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload.jsp)
URL: 
http://svn.apache.org/viewvc/struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp?p2=struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp&p1=struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload.jsp&r1=727129&r2=727179&rev=727179&view=diff
==============================================================================
--- 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload.jsp
 (original)
+++ 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp
 Tue Dec 16 13:53:05 2008
@@ -23,6 +23,7 @@
     <title>File Upload Example</title>
   </head>
   <body>
+<h2>Test for STRUTS-3173</h2>
 <logic:messagesPresent>
    <ul>
    <html:messages id="error">
@@ -35,11 +36,11 @@
             The most important part is to declare your form's enctype to be 
"multipart/form-data",
             and to have a form:file element that maps to your ActionForm's 
FormFile property
     -->
-    <html:form action="upload-submit.do?queryParam=Successful" 
enctype="multipart/form-data">
+    <html:form action="upload-submit2.do?queryParam=Successful" 
enctype="multipart/form-data">
     <p>Please enter some text, just to demonstrate the handling of text 
elements as opposed to file elements: <br />
     <html:text property="theText" errorStyle="background-color: yellow"/></p>
     <p>Please select the file that you would like to upload: <br />
-    <html:file property="theFile"  errorStyle="background-color: yellow" /></p>
+    <input type="file" name="otherFile" /></p>
     <p>If you would rather write this file to another file, please check here: 
<br />
     <html:checkbox property="writeFile" /></p>
     <p>If you checked the box to write to a file, please specify the file path 
here: <br />

Propchange: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp
------------------------------------------------------------------------------
    svn:keywords = author date id

Propchange: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/upload/upload2.jsp
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/welcome.jsp
URL: 
http://svn.apache.org/viewvc/struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/welcome.jsp?rev=727179&r1=727178&r2=727179&view=diff
==============================================================================
--- 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/welcome.jsp
 (original)
+++ 
struts/struts1/branches/STRUTS_1_3_BRANCH/apps/examples/src/main/webapp/welcome.jsp
 Tue Dec 16 13:53:05 2008
@@ -37,6 +37,7 @@
     <li><html:link module="/exercise" action="/welcome">Taglib Test 
Pages</html:link></li>
 
     <li><html:link module="/upload" action="/upload">Upload 
examples</html:link></li>
+    <li><html:link module="/upload" action="/upload2">Upload Test for 
STR-3173</html:link></li>
 
     <li><html:link module="/validator" action="/welcome">Validator and 
Localization examples</html:link></li>
 

Modified: 
struts/struts1/branches/STRUTS_1_3_BRANCH/core/src/main/java/org/apache/struts/util/RequestUtils.java
URL: 
http://svn.apache.org/viewvc/struts/struts1/branches/STRUTS_1_3_BRANCH/core/src/main/java/org/apache/struts/util/RequestUtils.java?rev=727179&r1=727178&r2=727179&view=diff
==============================================================================
--- 
struts/struts1/branches/STRUTS_1_3_BRANCH/core/src/main/java/org/apache/struts/util/RequestUtils.java
 (original)
+++ 
struts/struts1/branches/STRUTS_1_3_BRANCH/core/src/main/java/org/apache/struts/util/RequestUtils.java
 Tue Dec 16 13:53:05 2008
@@ -503,6 +503,10 @@
         try {
             Class propertyType = PropertyUtils.getPropertyType(bean, name);
 
+            if (propertyType == null) {
+                return parameterValue;
+            }
+
             if (List.class.isAssignableFrom(propertyType)) {
                 ArrayList list = new ArrayList(1);
                 list.add(formFileValue);


Reply via email to