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 2012/05/02 20:52:28 UTC
svn commit: r1333153 -
/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Author: markt
Date: Wed May 2 18:52:28 2012
New Revision: 1333153
URL: http://svn.apache.org/viewvc?rev=1333153&view=rev
Log:
No further read locks required but a few places where an NPE may occur.
Modified:
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1333153&r1=1333152&r2=1333153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Wed May 2 18:52:28 2012
@@ -712,12 +712,17 @@ public class GenericKeyedObjectPool<K,T>
final Map<PooledObject<T>, K> map = new TreeMap<PooledObject<T>, K>();
for (K k : poolMap.keySet()) {
- final LinkedBlockingDeque<PooledObject<T>> idleObjects =
- poolMap.get(k).getIdleObjects();
- for (PooledObject<T> p : idleObjects) {
- // each item into the map using the PooledObject object as the
- // key. It then gets sorted based on the idle time
- map.put(p, k);
+ ObjectDeque<T> queue = poolMap.get(k);
+ // Protect against possible NPE if key has been removed in another
+ // thread. Not worth locking the keys while this loop completes.
+ if (queue != null) {
+ final LinkedBlockingDeque<PooledObject<T>> idleObjects =
+ queue.getIdleObjects();
+ for (PooledObject<T> p : idleObjects) {
+ // each item into the map using the PooledObject object as the
+ // key. It then gets sorted based on the idle time
+ map.put(p, k);
+ }
}
}
@@ -1051,7 +1056,6 @@ public class GenericKeyedObjectPool<K,T>
private void deregister(K k) {
ObjectDeque<T> objectDeque;
- // TODO Think carefully about when a read lock is required
objectDeque = poolMap.get(k);
long numInterested = objectDeque.getNumInterested().decrementAndGet();
if (numInterested == 0 && objectDeque.getCreateCount().get() == 0) {
@@ -1088,6 +1092,10 @@ public class GenericKeyedObjectPool<K,T>
private void ensureMinIdle(K key) throws Exception {
// Calculate current pool objects
ObjectDeque<T> objectDeque = poolMap.get(key);
+ // Protect against NPEs in case the key has been removed
+ if (objectDeque == null) {
+ return;
+ }
// this method isn't synchronized so the
// calculateDeficit is done at the beginning