This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release18.12 by this push: new b21dff7 Fixed: DiskFileItem as request attribute creates problems (OFBIZ-12016) b21dff7 is described below commit b21dff75d845df3977e1d70e5d305145c843ec09 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Tue Oct 19 07:07:01 2021 +0200 Fixed: DiskFileItem as request attribute creates problems (OFBIZ-12016) This was related to reques-redirect usage with a file upload in the request. More info at the Jira... Thanks: Sebastian Berg and Benjamin Jugl for report --- .../org/apache/ofbiz/base/util/UtilObject.java | 26 +++------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java index e1908a8..33016fc 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java @@ -21,7 +21,6 @@ package org.apache.ofbiz.base.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Array; import java.util.Iterator; @@ -39,22 +38,7 @@ public final class UtilObject { private UtilObject() { } - public static final String module = UtilObject.class.getName(); - - public static byte[] getBytes(InputStream is) { - byte[] buffer = new byte[4 * 1024]; - byte[] data = null; - try (ByteArrayOutputStream bos = new ByteArrayOutputStream()){ - int numBytesRead; - while ((numBytesRead = is.read(buffer)) != -1) { - bos.write(buffer, 0, numBytesRead); - } - data = bos.toByteArray(); - } catch (IOException e) { - Debug.logError(e, module); - } - return data; - } + private static final String module = UtilObject.class.getName(); /** Serialize an object to a byte array */ public static byte[] getBytes(Object obj) { @@ -93,24 +77,20 @@ public final class UtilObject { Object obj = null; try { obj = getObjectException(bytes); - } catch (IOException e) { + } catch (IOException | ClassCastException | ClassNotFoundException e) { Debug.logError(e, module); - } catch (ClassNotFoundException e1) { - // DiskFileItem, FileItemHeadersImpl are not serializable. So SafeObjectInputStream::resolveClass return ClassNotFoundException - return null; } return obj; } /** * Deserializes a byte array back to an object. - * * @param bytes the array of bytes * @return the deserialized object. * @throws ClassNotFoundException when the class can not be deserialized. * @throws IOException when a general Input/Output error happen. */ - public static Object getObjectException(byte[] bytes) throws ClassNotFoundException, IOException { + public static Object getObjectException(byte[] bytes) throws ClassCastException, ClassNotFoundException, IOException { try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); SafeObjectInputStream wois = new SafeObjectInputStream(bis)) { return wois.readObject();