svn commit: r1857393 - in /ofbiz/ofbiz-framework/branches/release18.12: ./ framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java

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

svn commit: r1857393 - in /ofbiz/ofbiz-framework/branches/release18.12: ./ framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java

jleroux@apache.org
Author: jleroux
Date: Fri Apr 12 09:29:47 2019
New Revision: 1857393

URL: http://svn.apache.org/viewvc?rev=1857393&view=rev
Log:
"Applied fix from trunk for revision: 1857392 "
------------------------------------------------------------------------
r1857392 | jleroux | 2019-04-12 11:29:03 +0200 (ven. 12 avr. 2019) | 14 lignes

Improved: Improve ObjectInputStream class
(OFBIZ-10837)

Cleans and simplifies things in UtilObject.java and also handles patterns.
That's what we missed most when needing to update.

Fixes typos in SafeObjectInputStream class and add a commented line for a WIP in
resolveProxyClass method

Also includes work done in UtilObject.java for OFBIZ-9855
"Using try-with-resources with File IO Objects."



------------------------------------------------------------------------

Modified:
    ofbiz/ofbiz-framework/branches/release18.12/   (props changed)
    ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java
    ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java

Propchange: ofbiz/ofbiz-framework/branches/release18.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 12 09:29:47 2019
@@ -10,4 +10,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1849931,1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805,1851885,1851998,1852503,1852587,1852818,1852882,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1854683,1855078,1855083,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856212,1856405,1856455,1856459-1856460,1856484,1856598,1856610,1856613,1856617,1856667,1857152,1857154,1857173,1857180,1857213
+/ofbiz/ofbiz-framework/trunk:1849931,1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805,1851885,1851998,1852503,1852587,1852818,1852882,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1854683,1855078,1855083,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856212,1856405,1856455,1856459-1856460,1856484,1856598,1856610,1856613,1856617,1856667,1857152,1857154,1857173,1857180,1857213,1857392

Modified: ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java?rev=1857393&r1=1857392&r2=1857393&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/SafeObjectInputStream.java Fri Apr 12 09:29:47 2019
@@ -60,9 +60,9 @@ public class SafeObjectInputStream exten
     @Override
     protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
         if (!WHITELIST_PATTERN.matcher(classDesc.getName()).find()) {
-            Debug.logWarning("************************Incompatible class: " + classDesc.getName() +
+            Debug.logWarning("***Incompatible class***: " + classDesc.getName() +
                     ". Please see OFBIZ-10837.  Report to dev ML if you use OFBiz without changes. "
-                    + "Else add you class into UtilObject::getObjectException", "SafeObjectInputStream");
+                    + "Else add your class into UtilObject::getObjectException", "SafeObjectInputStream");
             throw new ClassCastException("Incompatible class: " + classDesc.getName());
         }
         
@@ -78,7 +78,8 @@ public class SafeObjectInputStream exten
         for (int i = 0; i < interfaces.length; i++) {
             cinterfaces[i] = classloader.loadClass(interfaces[i]);
         }
-
+        //Proxy.getInvocationHandler(proxy)
+        
         try {
             return Proxy.getProxyClass(classloader, cinterfaces);
         } catch (IllegalArgumentException e) {

Modified: ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java?rev=1857393&r1=1857392&r2=1857393&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java Fri Apr 12 09:29:47 2019
@@ -44,65 +44,27 @@ public final class UtilObject {
     public static byte[] getBytes(InputStream is) {
         byte[] buffer = new byte[4 * 1024];
         byte[] data = null;
-        try {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            try {
-
-                int numBytesRead;
-                while ((numBytesRead = is.read(buffer)) != -1) {
-                    bos.write(buffer, 0, numBytesRead);
-                }
-                data = bos.toByteArray();
-            } finally {
-                bos.close();
+        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);
-        } finally {
-            try {
-                if (is != null) {
-                    is.close();
-                }
-            } catch (IOException e) {
-                Debug.logError(e, module);
-            }
         }
-
         return data;
     }
 
     /** Serialize an object to a byte array */
     public static byte[] getBytes(Object obj) {
         byte[] data = null;
-        try {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            try {
-                ObjectOutputStream oos = new ObjectOutputStream(bos);
-                try {
-                    oos.writeObject(obj);
-                    data = bos.toByteArray();
-                } catch (IOException e) {
-                    Debug.logError(e, module);
-                } finally {
-                    oos.flush();
-                    oos.close();
-                }
-            } catch (IOException e) {
-                // I don't know how to force an error during flush or
-                // close of ObjectOutputStream; since OOS is wrapping
-                // BAOS, and BAOS does not throw IOException during
-                // write, I don't think this can happen.
-                Debug.logError(e, module);
-            } finally {
-                bos.close();
-            }
+        try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+            oos.writeObject(obj);
+            data = bos.toByteArray();
         } catch (IOException e) {
-            // How could this ever happen?  BAOS.close() is listed as
-            // throwing the exception, but I don't understand why this
-            // is.
             Debug.logError(e, module);
         }
-
         return data;
     }
 
@@ -142,14 +104,10 @@ public final class UtilObject {
         try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
                 SafeObjectInputStream wois = new SafeObjectInputStream(bis,
                         Thread.currentThread().getContextClassLoader(),
-                        java.util.Arrays.asList("byte\\[\\]", "Number", "Long", "foo", "SerializationInjector",
-                                "java.util.HashMap", "Boolean", "Number", "Integer", "FlexibleStringExpander",
-                                "sun.util.calendar.ZoneInfo", "java.sql.Timestamp", "java.util.Date",
-                                "java.math.BigDecimal", "\\[Z","\\[B","\\[S","\\[I","\\[J","\\[F","\\[D","\\[C",
-                                "org.apache.ofbiz.widget.renderer.VisualTheme",
-                                "org.apache.ofbiz.widget.model.ModelTheme",
-                                "java.util.Collections", "java.util.LinkedList", "java.util.ArrayList",
-                                "java.util.TimeZone"));) {
+                        java.util.Arrays.asList("byte\\[\\]", "foo", "SerializationInjector",
+                                "\\[Z","\\[B","\\[S","\\[I","\\[J","\\[F","\\[D","\\[C",
+                                "java..*", "sun.util.calendar..*", "org.apache.ofbiz..*"));) {
+                        // "foo" and, "SerializationInjector" are used in UtilObjectTests::testGetObject
             return wois.readObject();
         }
     }