Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 01B4DC847 for ; Wed, 2 May 2012 18:52:50 +0000 (UTC) Received: (qmail 98651 invoked by uid 500); 2 May 2012 18:52:49 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 98595 invoked by uid 500); 2 May 2012 18:52:49 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 98588 invoked by uid 99); 2 May 2012 18:52:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 May 2012 18:52:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 May 2012 18:52:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 93A10238890B for ; Wed, 2 May 2012 18:52:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1333153 - /commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Date: Wed, 02 May 2012 18:52:28 -0000 To: commits@commons.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120502185228.93A10238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 final Map, K> map = new TreeMap, K>(); for (K k : poolMap.keySet()) { - final LinkedBlockingDeque> idleObjects = - poolMap.get(k).getIdleObjects(); - for (PooledObject 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 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> idleObjects = + queue.getIdleObjects(); + for (PooledObject 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 private void deregister(K k) { ObjectDeque 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 private void ensureMinIdle(K key) throws Exception { // Calculate current pool objects ObjectDeque 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