commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r925180 - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool/ java/org/apache/commons/pool/impl/ test/org/apache/commons/pool/impl/
Date Fri, 19 Mar 2010 11:36:22 GMT
Author: markt
Date: Fri Mar 19 11:36:21 2010
New Revision: 925180

URL: http://svn.apache.org/viewvc?rev=925180&view=rev
Log:
Fix and expand failing OOME test case
Add consistent handling for Throwables that are normally swallowed including always re-throwing
certain Throwables

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/PoolUtils.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/PoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/PoolUtils.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/PoolUtils.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/PoolUtils.java Fri Mar 19 11:36:21
2010
@@ -51,6 +51,24 @@ public final class PoolUtils {
     }
 
     /**
+     * Should the supplied Throwable be re-thrown (eg if it is an instance of
+     * one of the Throwables that should never be swallowed). Used by the pool
+     * error handling for operations that throw exceptions that normally need to
+     * be ignored.
+     * @param t The Throwable to check
+     * @since Pool 1.5.5
+     */
+    public static void checkRethrow(Throwable t) {
+        if (t instanceof ThreadDeath) {
+            throw (ThreadDeath) t;
+        }
+        if (t instanceof VirtualMachineError) {
+            throw (VirtualMachineError) t;
+        }
+        // All other instances of Throwable will be silently swallowed
+    }
+
+    /**
      * Adapt a <code>KeyedPoolableObjectFactory</code> instance to work where
a <code>PoolableObjectFactory</code> is
      * needed. This method is the equivalent of calling
      * {@link #adapt(KeyedPoolableObjectFactory, Object) PoolUtils.adapt(aKeyedPoolableObjectFactory,
new Object())}.

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
Fri Mar 19 11:36:21 2010
@@ -32,6 +32,7 @@ import java.util.TimerTask;
 import org.apache.commons.pool.BaseKeyedObjectPool;
 import org.apache.commons.pool.KeyedObjectPool;
 import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.PoolUtils;
 
 /**
  * A configurable <code>KeyedObjectPool</code> implementation.
@@ -1212,10 +1213,12 @@ public class GenericKeyedObjectPool exte
                 }
                 return latch.getPair().value;
             } catch (Throwable e) {
+                PoolUtils.checkRethrow(e);
                 // object cannot be activated or is invalid
                 try {
                     _factory.destroyObject(key, latch.getPair().value);
                 } catch (Throwable e2) {
+                    PoolUtils.checkRethrow(e2);
                     // cannot destroy broken object
                 }
                 synchronized (this) {

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
Fri Mar 19 11:36:21 2010
@@ -27,6 +27,7 @@ import java.util.TimerTask;
 
 import org.apache.commons.pool.BaseObjectPool;
 import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.PoolUtils;
 import org.apache.commons.pool.PoolableObjectFactory;
 import org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair;
 
@@ -1183,10 +1184,12 @@ public class GenericObjectPool extends B
                 return latch.getPair().value;
             }
             catch (Throwable e) {
+                PoolUtils.checkRethrow(e);
                 // object cannot be activated or is invalid
                 try {
                     _factory.destroyObject(latch.getPair().value);
                 } catch (Throwable e2) {
+                    PoolUtils.checkRethrow(e2);
                     // cannot destroy broken object
                 }
                 synchronized (this) {

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
Fri Mar 19 11:36:21 2010
@@ -106,10 +106,12 @@ public class SoftReferenceObjectPool ext
                         throw new Exception("ValidateObject failed");
                     }
                 } catch (Throwable t) {
+                    PoolUtils.checkRethrow(t);
                     try {
                         _factory.destroyObject(obj);
                     } catch (Throwable t2) {
-                        // swallowed
+                        PoolUtils.checkRethrow(t2);
+                        // Swallowed
                     } finally {
                         obj = null;
                     }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
Fri Mar 19 11:36:21 2010
@@ -20,6 +20,7 @@ package org.apache.commons.pool.impl;
 import org.apache.commons.pool.BaseKeyedObjectPool;
 import org.apache.commons.pool.KeyedObjectPool;
 import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.PoolUtils;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -160,9 +161,11 @@ public class StackKeyedObjectPool extend
                         throw new Exception("ValidateObject failed");
                     }
                 } catch (Throwable t) {
+                    PoolUtils.checkRethrow(t);
                     try {
                         _factory.destroyObject(key,obj);
                     } catch (Throwable t2) {
+                        PoolUtils.checkRethrow(t2);
                         // swallowed
                     } finally {
                         obj = null;

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java Fri
Mar 19 11:36:21 2010
@@ -23,6 +23,7 @@ import java.util.Stack;
 
 import org.apache.commons.pool.BaseObjectPool;
 import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.PoolUtils;
 import org.apache.commons.pool.PoolableObjectFactory;
 
 /**
@@ -160,9 +161,11 @@ public class StackObjectPool extends Bas
                         throw new Exception("ValidateObject failed");
                     }
                 } catch (Throwable t) {
+                    PoolUtils.checkRethrow(t);
                     try {
                         _factory.destroyObject(obj);
                     } catch (Throwable t2) {
+                        PoolUtils.checkRethrow(t2);
                         // swallowed
                     } finally {
                         obj = null;

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java?rev=925180&r1=925179&r2=925180&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java
Fri Mar 19 11:36:21 2010
@@ -172,7 +172,28 @@ public class TestSoftRefOutOfMemory exte
             }
         });
 
-        pool.returnObject(pool.borrowObject());
+        try {
+            pool.borrowObject();
+            fail("Expected out of memory.");
+        }
+        catch (OutOfMemoryError ex) {
+            // expected
+        }
+        pool.close();
+        
+        pool = new SoftReferenceObjectPool(new BasePoolableObjectFactory() {
+            public Object makeObject() throws Exception {
+                return new Object();
+            }
+
+            public boolean validateObject(Object obj) {
+                throw new IllegalAccessError();
+            }
+
+            public void destroyObject(Object obj) throws Exception {
+                throw new OutOfMemoryError();
+            }
+        });
 
         try {
             pool.borrowObject();
@@ -182,6 +203,7 @@ public class TestSoftRefOutOfMemory exte
             // expected
         }
         pool.close();
+
     }
 
 



Mime
View raw message