commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 39052] New: - NullPointerException returning obj to pool during shutdown
Date Tue, 21 Mar 2006 20:14:53 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39052>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39052

           Summary: NullPointerException returning obj to pool during
                    shutdown
           Product: Commons
           Version: unspecified
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Pool
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: jasper_rosenberg@yahoo.com


This issue was reproduced with commons-dbcp-1.2.1 and commons-pool-1.2.  It is
really a pool issue, but was easiest to demonstrate using the layer dbcp.

The exception is:
-----------------------
java.lang.NullPointerException
	at
org.apache.commons.pool.impl.GenericObjectPool.addObjectToPool(GenericObjectPool.java:875)
	at
org.apache.commons.pool.impl.GenericObjectPool.returnObject(GenericObjectPool.java:854)
	at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:80)
	at
org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:180)
	at
org.quartz.utils.PoolingConnectionProviderTest.testShutdown(PoolingConnectionProviderTest.java:47)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

-----------------------

The problem is that GenericObjectPool.returnObject() asserts that the pool is
open before trying to return the connection to the pool, but
GenericObjectPool.close() nulls out the pool's fields before actually calling
the superclass BaseObjectPool.close() which is actually responsible for marking
the pool as closed.

So GenericObjectPool is in the middle of closing, having already nulled out the
underlying _pool member variable but not yet having set closed to true, when the
client tries to return an object. GenericObjectPool.returnObject() successfully
passes the assertOpen() check since closed is still set to false, but then it
blows up trying to return the connection to the underlying _pool which is null. 

The following unit test demonstrates the issue:

import java.sql.Connection;
import java.sql.SQLException;

import junit.framework.TestCase;

import org.apache.commons.dbcp.BasicDataSource;

public class BasicDataSourceTest extends TestCase {
    
    public void testShutdown() throws Exception {
        
        final BasicDataSource datasource = new BasicDataSource();
        datasource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        datasource.setUrl("jdbc:oracle:thin:@172.27.50.75:1521:devnlgv");
        datasource.setUsername("dev2_shop");
        datasource.setPassword("dev2_shop");
        
        final Connection conn = datasource.getConnection();
        
        new Thread() {
            public void run() {
                try {
                    datasource.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }.start();

        conn.close();
    }
}

To cause the NullPointerException, place a breakpoint at:
1. GenericObjectPool [line: 869] - addObjectToPool(Object, boolean)
2. GenericObjectPool [line: 896] - close()

Once both breakpoints are hit, let them continue and you will get the above
exception (this is with the latest dbcp and pool jars) 

This issue was originally noticed in the Quartz project:
http://jira.opensymphony.com/browse/QUARTZ-289

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message