Bug #13043 using property gatherPerfMetrics=true makes a NullPointerException with DBCP
Submitted: 7 Sep 2005 17:47 Modified: 4 Oct 2005 5:23
Reporter: M rt012
Status: Closed
Category:Connector/J Severity:S3 (Non-critical)
Version:3.1.10 OS:Microsoft Windows (windows server 2003)
Assigned to: Mark Matthews Target Version:

[7 Sep 2005 17:47] M rt012
Description:

Using Tomcat 5.0.28 and configuring a data source with DBCP pool in server.xml

When I add the properties gatherPerfMetrics=true and reportMetricsIntervalMillis=30000 to
the connection properties with a validation query "select 1", it results in an
NullPointerException when the pool try to initialize (during execution of the the
validation query).

Here is the interesting part of the stack trace : 

----- Root Cause -----
javax.servlet.ServletException: com._1genia.rnd.annuaire.persistence.PersistenceException:
net.sf.hibernate.JDBCException: Cannot open connection: Cannot create
PoolableConnectionFactory (Error during query: Unexpected Exception:
java.lang.NullPointerException message given: null

Nested Stack Trace:

** BEGIN NESTED EXCEPTION ** 

java.lang.NullPointerException

STACKTRACE:

java.lang.NullPointerException
	at com.mysql.jdbc.ResultSet.<init>(ResultSet.java:366)
	at com.mysql.jdbc.MysqlIO.buildResultSetWithRows(MysqlIO.java:1980)
	at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:429)
	at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:1959)
	at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1384)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1727)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
	at com.mysql.jdbc.Statement.executeQuery(Statement.java:822)
	at
org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:205)
	at
org.apache.commons.dbcp.PoolableConnectionFactory.validateConnection(PoolableConnectionFac
tory.java:328)
	at
org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:879
)
	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
	at
net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectio
nProvider.java:61)
	at net.sf.hibernate.impl.SessionFactoryImpl.openConnection(SessionFactoryImpl.java:417)
	at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:2861)
	at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:55)
	at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:480)
	at net.sf.hibernate.loader.Loader.doFind(Loader.java:136)
	at net.sf.hibernate.loader.Loader.find(Loader.java:606)
	at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:912)
	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1356)
	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1335)
	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1327)

How to repeat:
Configure a data source with Tomcat, here is mine : 

<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource" />
<ResourceParams name="jdbc/testdb">
    <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
        <name>maxActive</name>
        <value>50</value>
    </parameter>
    <parameter>
        <name>maxIdle</name>
        <value>10</value>
    </parameter>
    <parameter>
        <name>maxWait</name>
        <value>10000</value>
    </parameter>
    <parameter>
        <name>username</name>
        <value>root</value>
    </parameter>
    <parameter>
        <name>password</name>
        <value></value>
    </parameter>
    <parameter>
        <name>driverClassName</name>
        <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
        <name>url</name>
        <value>jdbc:mysql://localhost/test</value>
    </parameter>
    <parameter>
        <name>connectionProperties</name>
<value>autoReconnect=true;relaxAutoCommit=true;logSlowQueries=true;slowQueryThresholdMilli
s=2000;gatherPerfMetrics=true;reportMetricsIntervalMillis=30000
        </value>
    </parameter>
    <parameter>
        <name>validationQuery</name>
        <value>select 1</value>
    </parameter>
    <parameter>
        <name>minEvictableIdleTimeMillis</name>
        <value>1200000</value>
    </parameter>
    <parameter>
        <name>timeBetweenEvictionRunsMillis</name>
        <value>300000</value>
    </parameter>
    <parameter>
        <name>removeAbandoned</name>
        <value>true</value>
    </parameter>
    <parameter>
        <name>removeAbandonedTimeout</name>
        <value>60</value>
    </parameter>
    <parameter>
        <name>logAbandoned</name>
        <value>true</value>
    </parameter>
</ResourceParams>
[1 Oct 2005 1:48] Tetsuro Ikeda
I succeeded to reproduce this issue with MySQL 4.0.26. (latest 4.0.x version) on
Windows2000Professional.

The latest ver4.1.x(4.1.14) and ver5.1.x(5.1.13) are no problem.
[1 Oct 2005 15:25] Valeriy Kravchuk
Dear bug reporter,

What version of MySQL server do you use? Is it 4.0.x? Have you noted the previous comment?
[2 Oct 2005 12:21] M rt012
Yes. I use MySQL 4.0.15
[3 Oct 2005 18:18] Tetsuro Ikeda
The protocal of ResultSet from server to client is different between MySQL4.1+ and before
MySQL4.1.

If the "gatherPerfMetrics=true", a part of Connector/J's code for MySQL4.1+ is executed,
and then a NullPointerException is occured.

This is happened when the table which has no name is called by "SELECT ...".

Tomcat DataSource with DBCP calls "SELECT 1", so a NullPointerException is occured.

I already talk about this to Mark Matthews, so this bug will be fixed soon.
[4 Oct 2005 5:23] Mark Matthews
This is fixed for 3.1.11. The fix for testing should be in the nightly snapshot build
after Oct 4, 00:00 GMT, available at http://downloads.mysql.com/snapshots.php#connector-j

Thanks for the bug report!