Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 22A2C11616 for ; Fri, 15 Aug 2014 09:20:19 +0000 (UTC) Received: (qmail 40920 invoked by uid 500); 15 Aug 2014 09:20:18 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 40831 invoked by uid 500); 15 Aug 2014 09:20:18 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 40815 invoked by uid 99); 15 Aug 2014 09:20:18 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Aug 2014 09:20:18 +0000 Date: Fri, 15 Aug 2014 09:20:18 +0000 (UTC) From: "Sebastian Hinckel (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DBCP-412) dbcp2.PoolableConnection.close raises NullPointerException MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DBCP-412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14098378#comment-14098378 ] Sebastian Hinckel commented on DBCP-412: ---------------------------------------- The same problem still exists in the examples for the pooling driver. Adding poolableConnectionFactory.setPool(connectionPool) solves the problem here, too. > dbcp2.PoolableConnection.close raises NullPointerException > ---------------------------------------------------------- > > Key: DBCP-412 > URL: https://issues.apache.org/jira/browse/DBCP-412 > Project: Commons Dbcp > Issue Type: Bug > Affects Versions: 2.0 > Environment: Mac OSX, Java 7, SQLAzure > Reporter: Davide Caroselli > Priority: Minor > Labels: NullPointerException, PoolableConnection > Fix For: 2.0.1 > > Attachments: DBCP-412.patch > > > I found a critical error while closing a PoolableConnection. > Here's the code to reproduce the bug (largely copied from the example shown in the Apache DBCP site): > {code:title=PoolingDataSourceExample2.java|borderStyle=solid} > public static void main(String[] args) throws Throwable { > Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); > DataSource dataSource = setupDataSource(jdbcUrl); > Connection connection = null; > PreparedStatement statement = null; > ResultSet result = null; > try { > connection = dataSource.getConnection(); > statement = connection.prepareStatement("SELECT 1"); > result = statement.executeQuery(); > } finally { > result.close(); > statement.close(); > connection.close(); > } > } > public static DataSource setupDataSource(String connectURI) { > ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, null); > PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); > ObjectPool connectionPool = new GenericObjectPool<>(poolableConnectionFactory); > PoolingDataSource dataSource = new PoolingDataSource<>(connectionPool); > return dataSource; > } > {code} > When the code tries to close the connection (in the final block), an exception is raised: > {code:title=PoolingDataSourceExample2.java|borderStyle=solid} > Exception in thread "main" java.lang.NullPointerException > at org.apache.commons.dbcp2.PoolableConnection.close(PoolableConnection.java:151) > at org.apache.commons.dbcp2.DelegatingConnection.closeInternal(DelegatingConnection.java:235) > at org.apache.commons.dbcp2.DelegatingConnection.close(DelegatingConnection.java:218) > at org.apache.commons.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:212) > at dbcp.PoolingDataSourceExample2.closeQuietly(PoolingDataSourceExample2.java:64) > at dbcp.PoolingDataSourceExample2.main(PoolingDataSourceExample2.java:43){code} > As I can see, the problem is the "_pool" variable inside PoolableConnection but I could not find any solution. -- This message was sent by Atlassian JIRA (v6.2#6252)