From dev-return-188108-archive-asf-public=cust-asf.ponee.io@tomcat.apache.org Thu Jan 11 02:43:14 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 6A4EC18072F for ; Thu, 11 Jan 2018 02:43:14 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5A3AD160C41; Thu, 11 Jan 2018 01:43:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A0756160C2E for ; Thu, 11 Jan 2018 02:43:13 +0100 (CET) Received: (qmail 27243 invoked by uid 500); 11 Jan 2018 01:43:12 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 27233 invoked by uid 99); 11 Jan 2018 01:43:12 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jan 2018 01:43:12 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id DA3583A023A for ; Thu, 11 Jan 2018 01:43:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1820819 - in /tomcat/tc7.0.x/trunk: modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java webapps/docs/changelog.xml Date: Thu, 11 Jan 2018 01:43:11 -0000 To: dev@tomcat.apache.org From: kfujino@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20180111014311.DA3583A023A@svn01-us-west.apache.org> Author: kfujino Date: Thu Jan 11 01:43:11 2018 New Revision: 1820819 URL: http://svn.apache.org/viewvc?rev=1820819&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61312 Prevent NullPointerException when using the statement cache of connection that has been closed. Modified: tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java?rev=1820819&r1=1820818&r2=1820819&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java (original) +++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java Thu Jan 11 01:43:11 2018 @@ -25,6 +25,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; import org.apache.tomcat.jdbc.pool.ConnectionPool; import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty; import org.apache.tomcat.jdbc.pool.PooledConnection; @@ -34,6 +36,7 @@ import org.apache.tomcat.jdbc.pool.Poole * {@code CallableStatement} instances on a connection. */ public class StatementCache extends StatementDecoratorInterceptor { + private static final Log log = LogFactory.getLog(StatementCache.class); protected static final String[] ALL_TYPES = new String[] {PREPARE_STATEMENT,PREPARE_CALL}; protected static final String[] CALLABLE_TYPE = new String[] {PREPARE_CALL}; protected static final String[] PREPARED_TYPE = new String[] {PREPARE_STATEMENT}; @@ -197,16 +200,14 @@ public class StatementCache extends Stat } public CachedStatement isCached(Method method, Object[] args) { - @SuppressWarnings("unchecked") - ConcurrentHashMap cache = - (ConcurrentHashMap)pcon.getAttributes().get(STATEMENT_CACHE_ATTR); + ConcurrentHashMap cache = getCache(); + if (cache == null) return null; return cache.get(createCacheKey(method, args)); } public boolean cacheStatement(CachedStatement proxy) { - @SuppressWarnings("unchecked") - ConcurrentHashMap cache = - (ConcurrentHashMap)pcon.getAttributes().get(STATEMENT_CACHE_ATTR); + ConcurrentHashMap cache = getCache(); + if (cache == null) return false; if (proxy.getCacheKey()==null) { return false; } else if (cache.containsKey(proxy.getCacheKey())) { @@ -224,9 +225,8 @@ public class StatementCache extends Stat } public boolean removeStatement(CachedStatement proxy) { - @SuppressWarnings("unchecked") - ConcurrentHashMap cache = - (ConcurrentHashMap)pcon.getAttributes().get(STATEMENT_CACHE_ATTR); + ConcurrentHashMap cache = getCache(); + if (cache == null) return false; if (cache.remove(proxy.getCacheKey()) != null) { cacheSize.decrementAndGet(); return true; @@ -236,6 +236,17 @@ public class StatementCache extends Stat } /*end the actual statement cache*/ + protected ConcurrentHashMap getCache() { + PooledConnection pCon = this.pcon; + if (pCon == null) { + if (log.isWarnEnabled()) log.warn("Connection has already been closed or abandoned"); + return null; + } + @SuppressWarnings("unchecked") + ConcurrentHashMap cache = + (ConcurrentHashMap)pCon.getAttributes().get(STATEMENT_CACHE_ATTR); + return cache; + } protected class CachedStatement extends StatementDecoratorInterceptor.StatementProxy { boolean cached = false; Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1820819&r1=1820818&r2=1820819&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Jan 11 01:43:11 2018 @@ -131,6 +131,14 @@ + + + + 61312: Prevent NullPointerExceptionn when using + the statement cache of connection that has been closed. (kfujino) + + + --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org