Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPool.java Tue Jun 19 10:23:56 2018 @@ -77,18 +77,18 @@ public class GenericObjectPool<T> extend implements ObjectPool<T>, GenericObjectPoolMXBean, UsageTracking<T> { /** - * Create a new <code>GenericObjectPool</code> using defaults from + * Creates a new <code>GenericObjectPool</code> using defaults from * {@link GenericObjectPoolConfig}. * * @param factory The object factory to be used to create object instances * used by this pool */ public GenericObjectPool(final PooledObjectFactory<T> factory) { - this(factory, new GenericObjectPoolConfig()); + this(factory, new GenericObjectPoolConfig<T>()); } /** - * Create a new <code>GenericObjectPool</code> using a specific + * Creates a new <code>GenericObjectPool</code> using a specific * configuration. * * @param factory The object factory to be used to create object instances @@ -99,7 +99,7 @@ public class GenericObjectPool<T> extend * pool. */ public GenericObjectPool(final PooledObjectFactory<T> factory, - final GenericObjectPoolConfig config) { + final GenericObjectPoolConfig<T> config) { super(config, ONAME_BASE, config.getJmxNamePrefix()); @@ -112,12 +112,10 @@ public class GenericObjectPool<T> extend idleObjects = new LinkedBlockingDeque<>(config.getFairness()); setConfig(config); - - startEvictor(getTimeBetweenEvictionRunsMillis()); } /** - * Create a new <code>GenericObjectPool</code> that tracks and destroys + * Creates a new <code>GenericObjectPool</code> that tracks and destroys * objects that are checked out, but never returned to the pool. * * @param factory The object factory to be used to create object instances @@ -130,7 +128,7 @@ public class GenericObjectPool<T> extend * and removal. The configuration is used by value. */ public GenericObjectPool(final PooledObjectFactory<T> factory, - final GenericObjectPoolConfig config, final AbandonedConfig abandonedConfig) { + final GenericObjectPoolConfig<T> config, final AbandonedConfig abandonedConfig) { this(factory, config); setAbandonedConfig(abandonedConfig); } @@ -221,7 +219,7 @@ public class GenericObjectPool<T> extend } /** - * Whether or not abandoned object removal is configured for this pool. + * Gets whether or not abandoned object removal is configured for this pool. * * @return true if this pool is configured to detect and remove * abandoned objects @@ -232,7 +230,7 @@ public class GenericObjectPool<T> extend } /** - * Will this pool identify and log any abandoned objects? + * Gets whether this pool identifies and logs any abandoned objects. * * @return {@code true} if abandoned object removal is configured for this * pool and removal events are to be logged otherwise {@code false} @@ -246,8 +244,8 @@ public class GenericObjectPool<T> extend } /** - * Will a check be made for abandoned objects when an object is borrowed - * from this pool? + * Gets whether a check is made for abandoned objects when an object is borrowed + * from this pool. * * @return {@code true} if abandoned object removal is configured to be * activated by borrowObject otherwise {@code false} @@ -261,7 +259,7 @@ public class GenericObjectPool<T> extend } /** - * Will a check be made for abandoned objects when the evictor runs? + * Gets whether a check is made for abandoned objects when the evictor runs. * * @return {@code true} if abandoned object removal is configured to be * activated when the evictor runs otherwise {@code false} @@ -275,7 +273,7 @@ public class GenericObjectPool<T> extend } /** - * Obtain the timeout before which an object will be considered to be + * Obtains the timeout before which an object will be considered to be * abandoned by this pool. * * @return The abandoned object timeout in seconds if abandoned object @@ -297,7 +295,7 @@ public class GenericObjectPool<T> extend * * @see GenericObjectPoolConfig */ - public void setConfig(final GenericObjectPoolConfig conf) { + public void setConfig(final GenericObjectPoolConfig<T> conf) { setLifo(conf.getLifo()); setMaxIdle(conf.getMaxIdle()); setMinIdle(conf.getMinIdle()); @@ -310,11 +308,16 @@ public class GenericObjectPool<T> extend setTestWhileIdle(conf.getTestWhileIdle()); setNumTestsPerEvictionRun(conf.getNumTestsPerEvictionRun()); setMinEvictableIdleTimeMillis(conf.getMinEvictableIdleTimeMillis()); - setTimeBetweenEvictionRunsMillis( - conf.getTimeBetweenEvictionRunsMillis()); - setSoftMinEvictableIdleTimeMillis( - conf.getSoftMinEvictableIdleTimeMillis()); - setEvictionPolicyClassName(conf.getEvictionPolicyClassName()); + setTimeBetweenEvictionRunsMillis(conf.getTimeBetweenEvictionRunsMillis()); + setSoftMinEvictableIdleTimeMillis(conf.getSoftMinEvictableIdleTimeMillis()); + final EvictionPolicy<T> policy = conf.getEvictionPolicy(); + if (policy == null) { + // Use the class name (pre-2.6.0 compatible) + setEvictionPolicyClassName(conf.getEvictionPolicyClassName()); + } else { + // Otherwise, use the class (2.6.0 feature) + setEvictionPolicy(policy); + } setEvictorShutdownTimeoutMillis(conf.getEvictorShutdownTimeoutMillis()); } @@ -341,7 +344,7 @@ public class GenericObjectPool<T> extend } /** - * Obtain a reference to the factory used to create, destroy and validate + * Obtains a reference to the factory used to create, destroy and validate * the objects used by this pool. * * @return the factory @@ -362,7 +365,7 @@ public class GenericObjectPool<T> extend } /** - * Borrow an object from the pool using the specific waiting time which only + * Borrows an object from the pool using the specific waiting time which only * applies if {@link #getBlockWhenExhausted()} is true. * <p> * If there is one or more idle instance available in the pool, then an @@ -533,14 +536,7 @@ public class GenericObjectPool<T> extend return; // Object was abandoned and removed } - synchronized(p) { - final PooledObjectState state = p.getState(); - if (state != PooledObjectState.ALLOCATED) { - throw new IllegalStateException( - "Object has already been returned to this pool or is invalid"); - } - p.markReturning(); // Keep from being marked abandoned - } + markReturningState(p); final long activeTime = p.getActiveTimeMillis(); @@ -888,7 +884,7 @@ public class GenericObjectPool<T> extend final PooledObject<T> p; try { p = factory.makeObject(); - } catch (final Exception e) { + } catch (final Throwable e) { createCount.decrementAndGet(); throw e; } finally { @@ -976,7 +972,7 @@ public class GenericObjectPool<T> extend } /** - * Create an object, and place it into the pool. addObject() is useful for + * Creates an object, and place it into the pool. addObject() is useful for * "pre-loading" a pool with idle objects. * <p> * If there is no capacity available to add to the pool, this is a no-op @@ -994,7 +990,7 @@ public class GenericObjectPool<T> extend } /** - * Add the provided wrapped pooled object to the set of idle objects for + * Adds the provided wrapped pooled object to the set of idle objects for * this pool. The object must already be part of the pool. If {@code p} * is null, this is a no-op (no exception, but no impact on the pool). * @@ -1014,7 +1010,7 @@ public class GenericObjectPool<T> extend } /** - * Calculate the number of objects to test in a run of the idle object + * Calculates the number of objects to test in a run of the idle object * evictor. * * @return The number of objects to test for validity @@ -1029,7 +1025,7 @@ public class GenericObjectPool<T> extend } /** - * Recover abandoned objects which have been checked out but + * Recovers abandoned objects which have been checked out but * not used since longer than the removeAbandonedTimeout. * * @param ac The configuration to use to identify abandoned objects @@ -1085,7 +1081,7 @@ public class GenericObjectPool<T> extend private volatile String factoryType = null; /** - * Return an estimate of the number of threads currently blocked waiting for + * Returns an estimate of the number of threads currently blocked waiting for * an object from the pool. This is intended for monitoring only, not for * synchronization control. * @@ -1101,7 +1097,7 @@ public class GenericObjectPool<T> extend } /** - * Return the type - including the specific type rather than the generic - + * Returns the type - including the specific type rather than the generic - * of the factory. * * @return A string representation of the factory type
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/GenericObjectPoolConfig.java Tue Jun 19 10:23:56 2018 @@ -23,10 +23,12 @@ package org.apache.tomcat.dbcp.pool2.imp * <p> * This class is not thread-safe; it is only intended to be used to provide * attributes used when creating a pool. + * </p> * + * @param <T> Type of element pooled. * @since 2.0 */ -public class GenericObjectPoolConfig extends BaseObjectPoolConfig { +public class GenericObjectPoolConfig<T> extends BaseObjectPoolConfig<T> { /** * The default value for the {@code maxTotal} configuration attribute. @@ -133,10 +135,11 @@ public class GenericObjectPoolConfig ext this.minIdle = minIdle; } + @SuppressWarnings("unchecked") @Override - public GenericObjectPoolConfig clone() { + public GenericObjectPoolConfig<T> clone() { try { - return (GenericObjectPoolConfig) super.clone(); + return (GenericObjectPoolConfig<T>) super.clone(); } catch (final CloneNotSupportedException e) { throw new AssertionError(); // Can't happen } Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/LinkedBlockingDeque.java Tue Jun 19 10:23:56 2018 @@ -901,7 +901,7 @@ class LinkedBlockingDeque<E> extends Abs } /** - * Empty the queue to the specified collection. + * Drains the queue to the specified collection. * * @param c The collection to add the elements to * @@ -920,7 +920,7 @@ class LinkedBlockingDeque<E> extends Abs } /** - * Empty no more than the specified number of elements from the queue to the + * Drains no more than the specified number of elements from the queue to the * specified collection. * * @param c collection to add the elements to @@ -1330,7 +1330,7 @@ class LinkedBlockingDeque<E> extends Abs } /** - * Save the state of this deque to a stream (that is, serialize it). + * Saves the state of this deque to a stream (that is, serialize it). * * @serialData The capacity (int), followed by elements (each an * {@code Object}) in the proper order, followed by a null @@ -1354,7 +1354,7 @@ class LinkedBlockingDeque<E> extends Abs } /** - * Reconstitute this deque from a stream (that is, + * Reconstitutes this deque from a stream (that is, * deserialize it). * @param s the stream */ @@ -1379,8 +1379,7 @@ class LinkedBlockingDeque<E> extends Abs // Monitoring methods /** - * Returns true if there are threads waiting to take instances from this deque. - * See disclaimer on accuracy in + * Returns true if there are threads waiting to take instances from this deque. See disclaimer on accuracy in * {@link java.util.concurrent.locks.ReentrantLock#hasWaiters(Condition)}. * * @return true if there is at least one thread waiting on this deque's notEmpty condition. @@ -1395,9 +1394,8 @@ class LinkedBlockingDeque<E> extends Abs } /** - * Returns the length of the queue of threads waiting to take instances from this deque. - * See disclaimer on accuracy in - * {@link java.util.concurrent.locks.ReentrantLock#getWaitQueueLength(Condition)}. + * Returns the length of the queue of threads waiting to take instances from this deque. See disclaimer on accuracy + * in {@link java.util.concurrent.locks.ReentrantLock#getWaitQueueLength(Condition)}. * * @return number of threads waiting on this deque's notEmpty condition. */ @@ -1411,8 +1409,7 @@ class LinkedBlockingDeque<E> extends Abs } /** - * Interrupts the threads currently waiting to take an object from the pool. - * See disclaimer on accuracy in + * Interrupts the threads currently waiting to take an object from the pool. See disclaimer on accuracy in * {@link java.util.concurrent.locks.ReentrantLock#getWaitingThreads(Condition)}. */ public void interuptTakeWaiters() { Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/NoOpCallStack.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/NoOpCallStack.java?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/NoOpCallStack.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/NoOpCallStack.java Tue Jun 19 10:23:56 2018 @@ -26,13 +26,16 @@ import java.io.PrintWriter; */ public class NoOpCallStack implements CallStack { + /** + * Singleton instance. + */ public static final CallStack INSTANCE = new NoOpCallStack(); private NoOpCallStack() { } @Override - public boolean printStackTrace(PrintWriter writer) { + public boolean printStackTrace(final PrintWriter writer) { return false; } Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/PoolImplUtils.java Tue Jun 19 10:23:56 2018 @@ -32,84 +32,115 @@ class PoolImplUtils { /** * Identifies the concrete type of object that an object factory creates. * - * @param factory The factory to examine + * @param factoryClass + * The factory to examine * * @return the type of object the factory creates */ @SuppressWarnings("rawtypes") - static Class<?> getFactoryType(final Class<? extends PooledObjectFactory> factory) { - return (Class<?>) getGenericType(PooledObjectFactory.class, factory); + static Class<?> getFactoryType(final Class<? extends PooledObjectFactory> factoryClass) { + final Class<PooledObjectFactory> type = PooledObjectFactory.class; + final Object genericType = getGenericType(type, factoryClass); + if (genericType instanceof Integer) { + // POOL-324 org.apache.commons.pool2.impl.GenericObjectPool.getFactoryType() throws + // java.lang.ClassCastException + // + // A bit hackish, but we must handle cases when getGenericType() does not return a concrete types. + final ParameterizedType pi = getParameterizedType(type, factoryClass); + if (pi != null) { + final Type[] bounds = ((TypeVariable) pi.getActualTypeArguments()[((Integer) genericType).intValue()]).getBounds(); + if (bounds != null && bounds.length > 0) { + final Type bound0 = bounds[0]; + if (bound0 instanceof Class) { + return (Class<?>) bound0; + } + } + } + // last resort: Always return a Class + return Object.class; + } + return (Class<?>) genericType; } - /** - * Obtain the concrete type used by an implementation of an interface that - * uses a generic type. + * Obtains the concrete type used by an implementation of an interface that uses a generic type. * - * @param type The interface that defines a generic type - * @param clazz The class that implements the interface with a concrete type - * @param <T> The interface type + * @param type + * The interface that defines a generic type + * @param clazz + * The class that implements the interface with a concrete type + * @param <T> + * The interface type * * @return concrete type used by the implementation */ - private static <T> Object getGenericType(final Class<T> type, - final Class<? extends T> clazz) { + private static <T> Object getGenericType(final Class<T> type, final Class<? extends T> clazz) { + if (type == null || clazz == null) { + // Error will be logged further up the call stack + return null; + } // Look to see if this class implements the generic interface - - // Get all the interfaces - final Type[] interfaces = clazz.getGenericInterfaces(); - for (final Type iface : interfaces) { - // Only need to check interfaces that use generics - if (iface instanceof ParameterizedType) { - final ParameterizedType pi = (ParameterizedType) iface; - // Look for the generic interface - if (pi.getRawType() instanceof Class) { - if (type.isAssignableFrom((Class<?>) pi.getRawType())) { - return getTypeParameter( - clazz, pi.getActualTypeArguments()[0]); - } - } - } + final ParameterizedType pi = getParameterizedType(type, clazz); + if (pi != null) { + return getTypeParameter(clazz, pi.getActualTypeArguments()[0]); } // Interface not found on this class. Look at the superclass. @SuppressWarnings("unchecked") - final - Class<? extends T> superClazz = - (Class<? extends T>) clazz.getSuperclass(); + final Class<? extends T> superClass = (Class<? extends T>) clazz.getSuperclass(); - final Object result = getGenericType(type, superClazz); + final Object result = getGenericType(type, superClass); if (result instanceof Class<?>) { - // Superclass implements interface and defines explicit type for - // generic + // Superclass implements interface and defines explicit type for generic return result; } else if (result instanceof Integer) { - // Superclass implements interface and defines unknown type for - // generic + // Superclass implements interface and defines unknown type for generic // Map that unknown type to the generic types defined in this class - final ParameterizedType superClassType = - (ParameterizedType) clazz.getGenericSuperclass(); - return getTypeParameter(clazz, - superClassType.getActualTypeArguments()[ - ((Integer) result).intValue()]); + final ParameterizedType superClassType = (ParameterizedType) clazz.getGenericSuperclass(); + return getTypeParameter(clazz, superClassType.getActualTypeArguments()[((Integer) result).intValue()]); } else { // Error will be logged further up the call stack return null; } } + /** + * Gets the matching parameterized type or null. + * @param type + * The interface that defines a generic type + * @param clazz + * The class that implements the interface with a concrete type + * @param <T> + * The interface type + */ + private static <T> ParameterizedType getParameterizedType(final Class<T> type, final Class<? extends T> clazz) { + for (final Type iface : clazz.getGenericInterfaces()) { + // Only need to check interfaces that use generics + if (iface instanceof ParameterizedType) { + final ParameterizedType pi = (ParameterizedType) iface; + // Look for the generic interface + if (pi.getRawType() instanceof Class) { + if (type.isAssignableFrom((Class<?>) pi.getRawType())) { + return pi; + } + } + } + } + return null; + } /** - * For a generic parameter, return either the Class used or if the type - * is unknown, the index for the type in definition of the class + * For a generic parameter, return either the Class used or if the type is unknown, the index for the type in + * definition of the class * - * @param clazz defining class - * @param argType the type argument of interest + * @param clazz + * defining class + * @param argType + * the type argument of interest * - * @return An instance of {@link Class} representing the type used by the - * type parameter or an instance of {@link Integer} representing - * the index for the type in the definition of the defining class + * @return An instance of {@link Class} representing the type used by the type parameter or an instance of + * {@link Integer} representing the index for the type in the definition of the defining class */ private static Object getTypeParameter(final Class<?> clazz, final Type argType) { if (argType instanceof Class<?>) { Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/pool2/impl/SoftReferenceObjectPool.java Tue Jun 19 10:23:56 2018 @@ -78,7 +78,7 @@ public class SoftReferenceObjectPool<T> } /** - * Borrow an object from the pool. If there are no idle instances available + * Borrows an object from the pool. If there are no idle instances available * in the pool, the configured factory's * {@link PooledObjectFactory#makeObject()} method is invoked to create a * new instance. @@ -243,7 +243,7 @@ public class SoftReferenceObjectPool<T> } /** - * Create an object, and place it into the pool. addObject() is useful for + * Creates an object, and places it into the pool. addObject() is useful for * "pre-loading" a pool with idle objects. * <p> * Before being added to the pool, the newly created instance is @@ -313,7 +313,7 @@ public class SoftReferenceObjectPool<T> } /** - * Return the number of instances currently borrowed from this pool. + * Returns the number of instances currently borrowed from this pool. * * @return the number of instances currently borrowed from this pool */ @@ -345,7 +345,7 @@ public class SoftReferenceObjectPool<T> } /** - * Close this pool, and free any resources associated with it. Invokes + * Closes this pool, and frees any resources associated with it. Invokes * {@link #clear()} to destroy and remove instances in the pool. * <p> * Calling {@link #addObject} or {@link #borrowObject} after invoking this @@ -382,7 +382,7 @@ public class SoftReferenceObjectPool<T> } /** - * Find the PooledSoftReference in allReferences that points to obj. + * Finds the PooledSoftReference in allReferences that points to obj. * * @param obj returning object * @return PooledSoftReference wrapping a soft reference to obj @@ -399,7 +399,7 @@ public class SoftReferenceObjectPool<T> } /** - * Destroy a {@code PooledSoftReference} and remove it from the idle and all + * Destroys a {@code PooledSoftReference} and removes it from the idle and all * references pools. * * @param toDestroy PooledSoftReference to destroy Modified: tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml?rev=1833801&r1=1833800&r2=1833801&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Tue Jun 19 10:23:56 2018 @@ -275,6 +275,10 @@ pick up the latest Windows binaries built with APR 1.6.3 and OpenSSL 1.0.2o. (markt) </update> + <update> + <bug>62458</bug>: Update the internal fork of Commons Pool to dfef97b + (2018-06-18) to pick up some bug fixes and enhancements. (markt) + </update> </changelog> </subsection> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org