Bug #33734 Null pointer Exception in canHandleAsServerPreparedStatement in ConnectionImpl
Submitted: 8 Jan 2008 5:03 Modified: 25 Feb 2008 12:11
Reporter: Jason Clawson Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:6.0-nightly-20080107 OS:Any
Assigned to: CPU Architecture:Any
Tags: null pointer exception

[8 Jan 2008 5:03] Jason Clawson
Description:
I get a null pointer exception with the latest nightly build when cachePrepStmts is set to true.

The offending line looks like:

synchronized (this.serverSideStatementCheckCache) {

Stack trace:

Exception in thread "main" java.lang.NullPointerException
	at com.mysql.jdbc.ConnectionImpl.canHandleAsServerPreparedStatement(ConnectionImpl.java:912)
	at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4089)
	at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4042)

How to repeat:
PreparedStatement newStatement = myConnection.prepareStatement(sql);

Ensure cachePrepStmts is true.
Ensure useServerPrepStmts is false.

Suggested fix:
It looks like the spinlock is initialized in createPreparedStatementCaches() which is only called if cachePrepStmts is set to true.  this.serverSideStatementCheckCache is only set if both cachePrepStmts and useServerPrepStmts are set to true.

I am not sure why I don't get a null pointer exception when cachePrepStmts and useServerPrepStmts is false.  I haven't had time to look into that yet.  I will try to look more into it tomorrow.
[8 Jan 2008 5:37] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/40658
[8 Jan 2008 5:44] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/40659
[25 Feb 2008 12:11] MC Brown
A note has been added to the 5.1.6 changelog: 

A NullPointerException could be raised when using client-side prepared statements and enabled the prepared statement cache using the cachePrepStmts.