Bug #30007 NPE in PreparedStatement getConnection() method
Submitted: 24 Jul 2007 15:15 Modified: 6 Aug 2007 6:22
Reporter: Cedric Wider Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1-nightly-20051124-bin.patched.ExportC OS:Any
Assigned to: CPU Architecture:Any

[24 Jul 2007 15:15] Cedric Wider
Description:
I am using the "mysql-connector-java-3.1-nightly-20051124-bin.patched.ExportControlled.jar" library to make connections to a MySQL database.

I have a method where I make the following statement:

[code]

public void closeConnection ( ResultSet rs, Statement stmt, Connection conn ) {

...
 if ( stmt != null ) {
    Connection innerConn = null;
    try {
        innerConn = stmt.getConnection();
    } catch (SQLException e) {...}
...

[/code]

Sometimes, not too often, it happens that the getConnection-call on the Statement Object causes the following NullPointerException:

Stack-Trace:
java.lang.NullPointerException: null

com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:516)
com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:507)
com.mysql.jdbc.PreparedStatement.toString(PreparedStatement.java:3286)
org.apache.commons.dbcp.DelegatingPreparedStatement.toString(DelegatingPrepa
redStatement.java:211)
org.apache.commons.dbcp.DelegatingStatement.checkOpen(DelegatingStatement.ja
va:137)
org.apache.commons.dbcp.DelegatingStatement.getConnection(DelegatingStatemen
t.java:201)
org.homelinux.ced.db.RootDatabase.closeConnection(RootDatabase.java:222)
...

How to repeat:
Unfortunately I haven't yet found a way to reproduce that Bug in a testing environment.
[24 Jul 2007 16:40] Mark Matthews
This is a pretty old release, and I notice that in the current 3.1 or 5.0 exception shouldn't happen, as the driver will check if the statement is closed or something would cause a NPE in that code path.

Can you upgrade?
[25 Jul 2007 18:26] Cedric Wider
Yes I guess it's possible to upgrade. Thanks!
[31 Jul 2007 19:39] Tonci Grgin
So Cedric, any news?
[3 Aug 2007 16:25] Cedric Wider
Upgraded to the newest Version of the driver and it didn't happen again. But since I haven't been able to reproduce the bug in a testing environment, I am not sure if this really means something.

However, I am happy so far with the newer version and trust you that the bug I reported is fixed.
[6 Aug 2007 6:22] Tonci Grgin
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at

  http://www.mysql.com/downloads/

Explanation: Hi Cedric. I am glad your problem doesn't show up any more. Thanks for your interest in MySQL.