[ofbiz-framework] branch trunk updated: Fixed: NotSerializableException using uploadPartyContentFile service (OFBIZ-12050)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Fixed: NotSerializableException using uploadPartyContentFile service (OFBIZ-12050)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new ae5d3b4  Fixed: NotSerializableException using uploadPartyContentFile service (OFBIZ-12050)
ae5d3b4 is described below

commit ae5d3b404586672344562956fa8f23d4c248b300
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Fri Nov 6 10:59:58 2020 +0100

    Fixed: NotSerializableException using uploadPartyContentFile service (OFBIZ-12050)
   
    This error appears after trying to upload a file to party content:
   
    2020-11-06 07:48:22,488 |jsse-nio-8443-exec-7 |RequestHandler                |I|
    Sending redirect to:
    [https://localhost:8443/partymgr/control/viewprofile?partyId=admin].
    2020-11-06 07:48:29,288 |jsse-nio-8443-exec-7 |UtilObject                    |E|
    null
    java.io.NotSerializableException: org.apache.commons.fileupload.disk.DiskFileItem
---
 .../main/java/org/apache/ofbiz/base/util/UtilMisc.java | 18 ++++++++++++++++--
 .../apache/ofbiz/webapp/control/RequestHandler.java    |  7 +++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
index 3b080bb..3381038 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
@@ -186,7 +186,6 @@ public final class UtilMisc {
                 if (Debug.verboseOn()) {
                     Debug.logVerbose("Found Map value that is not Serializable: " + mapEntry.getKey() + "=" + mapEntry.getValue(), MODULE);
                 }
-
             }
         }
         for (String keyToRemove : keysToRemove) {
@@ -195,9 +194,24 @@ public final class UtilMisc {
     }
 
     /**
+     * This change an ArrayList to be Serializable by removing all entries that are not Serializable.
+     * @param arrayList
+     */
+    public static <V> void makeArrayListSerializable(ArrayList<Object> arrayList) {
+        // now filter out all non-serializable values
+        Iterator itr = arrayList.iterator();
+        while (itr.hasNext()) {
+            Object obj = itr.next();
+            if (!(obj instanceof Serializable)) {
+                itr.remove();
+            }
+        }
+    }
+
+    /**
      * Sort a List of Maps by specified consistent keys.
      * @param listOfMaps List of Map objects to sort.
-     * @param sortKeys   List of Map keys to sort by.
+     * @param sortKeys List of Map keys to sort by.
      * @return a new List of sorted Maps.
      */
     public static List<Map<Object, Object>> sortMaps(List<Map<Object, Object>> listOfMaps, List<? extends String> sortKeys) {
diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
index 3de4b30..87d94c7 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
@@ -25,6 +25,7 @@ import java.io.Serializable;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.cert.X509Certificate;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -249,6 +250,12 @@ public class RequestHandler {
                     // See OFBIZ-750 and OFBIZ-11123 for cases where a value in an inner Map is not serializable
                     UtilMisc.makeMapSerializable(UtilGenerics.cast(obj));
                 }
+                if (obj instanceof ArrayList) {
+                    // See OFBIZ-12050 for cases where a value in an ArrayList is not serializable
+                    @SuppressWarnings("unchecked")
+                    ArrayList<Object> arrayList = (ArrayList<Object>) obj;
+                    UtilMisc.makeArrayListSerializable(arrayList);
+                }
                 reqAttrMap.put(name, obj);
             }
         }