Author: jleroux
Date: Tue May  7 21:09:47 2013
New Revision: 1480079

URL: http://svn.apache.org/r1480079
Log:
A sligthly modified patch from Christoph Neuroth for "Exceptions logged when 
caches contain collections with unserializable objects" 
https://issues.apache.org/jira/browse/OFBIZ-5184

jacopoc commited revision 1352575 which would prevent stack traces to be logged 
when viewing the cache overview screen in /webtools. However, a stacktrace is 
still logged when the caches contain collections which themselves contain 
objects which cannot be serialized.

jleroux: I simply used logWarning instead of info

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=1480079&r1=1480078&r2=1480079&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 Tue 
May  7 21:09:47 2013
@@ -19,6 +19,7 @@
 package org.ofbiz.base.util.cache;
 
 import java.io.IOException;
+import java.io.NotSerializableException;
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Collections;
@@ -49,8 +50,8 @@ import org.ofbiz.base.util.UtilObject;
 import org.ofbiz.base.util.UtilValidate;
 
 import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
-import com.googlecode.concurrentlinkedhashmap.EvictionListener;
 import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder;
+import com.googlecode.concurrentlinkedhashmap.EvictionListener;
 
 /**
  * Generalized caching utility. Provides a number of caching features:
@@ -507,6 +508,13 @@ public class UtilCache<K, V> implements 
                 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 (NotSerializableException e) {
+            // this happens when we try to get the byte count for an object 
which itself is
+            // serializable, but fails to be serialized, such as a map holding 
unserializable objects
+            if (Debug.warningOn()) {
+                Debug.logWarning("NotSerializableException while computing 
memory size; returning 0 byte size for object of " + e.getMessage(), module);
+            }
+            return 0;
         } catch (Exception e) {
             Debug.logWarning(e, "Unable to compute memory size for object of " 
+ o.getClass(), module);
             return 0;


Reply via email to