You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2015/05/14 10:58:50 UTC

svn commit: r1679326 - in /commons/proper/pool/trunk/src: changes/changes.xml main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java

Author: markt
Date: Thu May 14 08:58:49 2015
New Revision: 1679326

URL: http://svn.apache.org/r1679326
Log:
Fix POOL-289.
Patch by Luke Winkenbach
Fixed class loading for custom EvictionPolicy implementations that may not be present in the class loader hierarchy of the Pool classes by falling back to the class loader of the current class.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1679326&r1=1679325&r2=1679326&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Thu May 14 08:58:49 2015
@@ -48,6 +48,11 @@ The <action> type attribute can be add,u
       Fixed capacity leak when an object is offered from a GenericKeyedObjectPool while it is
       being validated by the evictor. 
     </action>
+    <action dev="markt" type="fix" issues="POOL-289" due-to="Luke Winkenbach">
+      Fixed class loading for custom EvictionPolicy implementations that may not
+      be present in the class loader hierarchy of the Pool classes by falling
+      back to the class loader of the current class.
+    </action>
   </release>
   <release version="2.3" date="2014-12-30" description=
 "This is a maintenance release that includes bug fixes and minor enhancements.">  

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java?rev=1679326&r1=1679325&r2=1679326&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java Thu May 14 08:58:49 2015
@@ -586,7 +586,9 @@ public abstract class BaseGenericObjectP
 
     /**
      * Sets the name of the {@link EvictionPolicy} implementation that is
-     * used by this pool.
+     * used by this pool. The Pool will attempt to load the class using the
+     * thread context class loader. If that fails, the Pool will attempt to load
+     * the class using the class loader that loaded this class.
      *
      * @param evictionPolicyClassName   the fully qualified class name of the
      *                                  new eviction policy
@@ -596,8 +598,13 @@ public abstract class BaseGenericObjectP
     public final void setEvictionPolicyClassName(
             String evictionPolicyClassName) {
         try {
-            Class<?> clazz = Class.forName(evictionPolicyClassName, true,
-                    Thread.currentThread().getContextClassLoader());
+            Class<?> clazz;
+            try {
+                clazz = Class.forName(evictionPolicyClassName, true,
+                        Thread.currentThread().getContextClassLoader());
+            } catch (ClassNotFoundException e) {
+                clazz = Class.forName(evictionPolicyClassName);
+            }
             Object policy = clazz.newInstance();
             if (policy instanceof EvictionPolicy<?>) {
                 @SuppressWarnings("unchecked") // safe, because we just checked the class
@@ -1101,7 +1108,7 @@ public abstract class BaseGenericObjectP
             return (long) result;
         }
     }
-    
+
     /**
      * The idle object eviction iterator. Holds a reference to the idle objects.
      */
@@ -1149,7 +1156,7 @@ public abstract class BaseGenericObjectP
         public void remove() {
             idleObjectIterator.remove();
         }
-        
+
     }
     
     /**