svn commit: r1352575 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java

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

svn commit: r1352575 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java

jacopoc
Author: jacopoc
Date: Thu Jun 21 15:42:45 2012
New Revision: 1352575

URL: http://svn.apache.org/viewvc?rev=1352575&view=rev
Log:
Improved information logged when the method is unable to compute the approximate byte size of a cached object using serialization: instead of a useless stack trace it is returned an informative message with the name of the class that is not serializable; in case of null objects a message is also logged.


Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java?rev=1352575&r1=1352574&r2=1352575&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java Thu Jun 21 15:42:45 2012
@@ -497,9 +497,18 @@ public class UtilCache<K, V> implements
 
     private long findSizeInBytes(Object o) {
         try {
-            return UtilObject.getByteCount(o);
+            if (o == null) {
+                if (Debug.infoOn()) Debug.logInfo("Found null object in cache: " + getName(), module);
+                return 0;
+            }
+            if (o instanceof Serializable) {
+                return UtilObject.getByteCount(o);
+            } else {
+                if (Debug.infoOn()) Debug.logInfo("Unable to compute memory size for non serializable object; returning 0 byte size for object of " + o.getClass(), module);
+                return 0;
+            }
         } catch (Exception e) {
-            e.printStackTrace();
+            Debug.logWarning(e, "Unable to compute memory size for object of " + o.getClass(), module);
             return 0;
         }
     }