Modified:
branches/branch_5_1/CHANGES
branches/branch_5_1/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java
branches/branch_5_1/src/testsuite/regression/PooledConnectionRegressionTest.java
Log:
Fixed BUG#35489 - Prepared statements from pooled connections cause NPE when closed()
under JDBC-4.0.
Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES 2008-06-25 00:44:22 UTC (rev 6792)
+++ branches/branch_5_1/CHANGES 2008-07-16 14:59:08 UTC (rev 6793)
@@ -49,6 +49,8 @@
The JDBC-3.0 (and earlier) specification has a bug, but you can get the buggy behavior
(allowing column names *and* labels to be used for ResultSet.findColumn() and
get...(String)) by setting
"useColumnNamesInFindColumn" to "true".
+
+ - Fixed BUG#35489 - Prepared statements from pooled connections cause NPE when closed()
under JDBC-4.0.
03-06-08 - Version 5.1.6
Modified:
branches/branch_5_1/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java
===================================================================
---
branches/branch_5_1/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java 2008-06-25
00:44:22 UTC (rev 6792)
+++
branches/branch_5_1/src/com/mysql/jdbc/jdbc2/optional/JDBC4PreparedStatementWrapper.java 2008-07-16
14:59:08 UTC (rev 6793)
@@ -62,13 +62,28 @@
super(c, conn, toWrap);
}
- public void close() throws SQLException {
+ public synchronized void close() throws SQLException {
+ if (this.pooledConnection == null) {
+ // no-op
+ return;
+ }
+
+ MysqlPooledConnection con = this.pooledConnection; // we need this
+ // later...
+
try {
super.close();
} finally {
try {
- ((JDBC4MysqlPooledConnection)this.pooledConnection).fireStatementEvent(
- new StatementEvent(this.pooledConnection, this));
+ StatementEvent e = new StatementEvent(con, this);
+ // todo: pull this all up into base classes when we support *only* JDK6 or newer
+ if (con instanceof JDBC4MysqlPooledConnection) {
+ ((JDBC4MysqlPooledConnection) con).fireStatementEvent(e);
+ } else if (con instanceof JDBC4MysqlXAConnection) {
+ ((JDBC4MysqlXAConnection) con).fireStatementEvent(e);
+ } else if (con instanceof JDBC4SuspendableXAConnection) {
+ ((JDBC4SuspendableXAConnection) con).fireStatementEvent(e);
+ }
} finally {
this.unwrappedInterfaces = null;
}
Modified: branches/branch_5_1/src/testsuite/regression/PooledConnectionRegressionTest.java
===================================================================
---
branches/branch_5_1/src/testsuite/regression/PooledConnectionRegressionTest.java 2008-06-25
00:44:22 UTC (rev 6792)
+++
branches/branch_5_1/src/testsuite/regression/PooledConnectionRegressionTest.java 2008-07-16
14:59:08 UTC (rev 6793)
@@ -42,6 +42,8 @@
import com.mysql.jdbc.PacketTooBigException;
import com.mysql.jdbc.jdbc2.optional.ConnectionWrapper;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
+import com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection;
+import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource;
/**
* Tests a PooledConnection implementation provided by a JDBC driver. Test case
@@ -407,4 +409,35 @@
System.out.println("Connection error: " + event.getSQLException());
}
}
-}
+
+ /**
+ * Tests fix for BUG#35489 - Prepared statements from pooled connections cause NPE
+ * when closed() under JDBC4
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug35489() throws Exception {
+ try {
+ MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
+ pds.setUrl(dbUrl);
+ this.pstmt = pds.getPooledConnection().getConnection().prepareStatement("SELECT 1");
+ this.pstmt.execute();
+ this.pstmt.close();
+
+ MysqlXADataSource xads = new MysqlXADataSource();
+ xads.setUrl(dbUrl);
+ this.pstmt = xads.getXAConnection().getConnection().prepareStatement("SELECT 1");
+ this.pstmt.execute();
+ this.pstmt.close();
+
+ xads = new MysqlXADataSource();
+ xads.setUrl(dbUrl);
+ xads.setPinGlobalTxToPhysicalConnection(true);
+ this.pstmt = xads.getXAConnection().getConnection().prepareStatement("SELECT 1");
+ this.pstmt.execute();
+ this.pstmt.close();
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+}
\ No newline at end of file
| Thread |
|---|
| • Connector/J commit: r6793 - in branches/branch_5_1: . src/com/mysql/jdbc/jdbc2/optional src/testsuite/regression | mmatthews | 16 Jul |