From: Date: March 9 2006 10:49pm Subject: Connector/J commit: r5040 - in branches: branch_3_1/connector-j branch_3_1/connector-j/src/com/mysql/jdbc branch_3_1/connector-j/src/testsuite/regression branch_5_0/connector-j branch_5_0/connector-j/src/com/mysql/jdbc branch_5_0/connector-j/src/testsuite/regression branch_5_1/connector-j branch_5_1/connector-j/src/com/mysql/jdbc branch_5_1/connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/3674 X-Bug: 17587 Message-Id: <200603092149.k29Ln7HY005765@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_3_1/connector-j/CHANGES branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java branches/branch_5_1/connector-j/CHANGES branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java Log: Fixed BUG#17587 - clearParameters() on a closed prepared statement causes NPE. Modified: branches/branch_3_1/connector-j/CHANGES =================================================================== --- branches/branch_3_1/connector-j/CHANGES 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_3_1/connector-j/CHANGES 2006-03-09 21:49:02 UTC (rev 5040) @@ -70,6 +70,9 @@ parameters pre-populated. Still waiting for feedback from JDBC experts group to determine what correct parameter count from getMetaData() should be, however. + + - Fixed BUG#17587 - clearParameters() on a closed prepared statement + causes NPE. 11-30-05 - Version 3.1.12 Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java =================================================================== --- branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -603,7 +603,9 @@ * @exception SQLException * if a database access error occurs */ - public void clearParameters() throws SQLException { + public synchronized void clearParameters() throws SQLException { + checkClosed(); + for (int i = 0; i < this.parameterValues.length; i++) { this.parameterValues[i] = null; this.parameterStreams[i] = null; Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java =================================================================== --- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -414,7 +414,8 @@ /** * @see java.sql.PreparedStatement#clearParameters() */ - public void clearParameters() throws SQLException { + public synchronized void clearParameters() throws SQLException { + checkClosed(); clearParametersInternal(true); } Modified: branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java =================================================================== --- branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -3050,4 +3050,38 @@ assertNotNull(pStmt.getGeneratedKeys()); } } + + /** + * Tests fix for BUG#17587 - clearParameters() on a closed prepared statement + * causes NPE. + * + * @throws Exception if the test fails. + */ + public void testBug17587() throws Exception { + createTable("testBug17857", "(field1 int)"); + PreparedStatement pStmt = null; + + try { + pStmt = conn.prepareStatement("INSERT INTO testBug17857 VALUES (?)"); + pStmt.close(); + try { + pStmt.clearParameters(); + } catch (SQLException sqlEx) { + assertEquals("08003", sqlEx.getSQLState()); + } + + pStmt = ((com.mysql.jdbc.Connection)conn).clientPrepareStatement("INSERT INTO testBug17857 VALUES (?)"); + pStmt.close(); + try { + pStmt.clearParameters(); + } catch (SQLException sqlEx) { + assertEquals("08003", sqlEx.getSQLState()); + } + + } finally { + if (pStmt != null) { + pStmt.close(); + } + } + } } Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_0/connector-j/CHANGES 2006-03-09 21:49:02 UTC (rev 5040) @@ -173,6 +173,9 @@ parameters pre-populated. Still waiting for feedback from JDBC experts group to determine what correct parameter count from getMetaData() should be, however. + + - Fixed BUG#17587 - clearParameters() on a closed prepared statement + causes NPE. 11-30-05 - Version 3.1.12 Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -597,7 +597,9 @@ * @exception SQLException * if a database access error occurs */ - public void clearParameters() throws SQLException { + public synchronized void clearParameters() throws SQLException { + checkClosed(); + for (int i = 0; i < this.parameterValues.length; i++) { this.parameterValues[i] = null; this.parameterStreams[i] = null; Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -423,7 +423,8 @@ /** * @see java.sql.PreparedStatement#clearParameters() */ - public void clearParameters() throws SQLException { + public synchronized void clearParameters() throws SQLException { + checkClosed(); clearParametersInternal(true); } Modified: branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -3078,4 +3078,38 @@ } } } + + /** + * Tests fix for BUG#17587 - clearParameters() on a closed prepared statement + * causes NPE. + * + * @throws Exception if the test fails. + */ + public void testBug17587() throws Exception { + createTable("testBug17857", "(field1 int)"); + PreparedStatement pStmt = null; + + try { + pStmt = conn.prepareStatement("INSERT INTO testBug17857 VALUES (?)"); + pStmt.close(); + try { + pStmt.clearParameters(); + } catch (SQLException sqlEx) { + assertEquals("08003", sqlEx.getSQLState()); + } + + pStmt = ((com.mysql.jdbc.Connection)conn).clientPrepareStatement("INSERT INTO testBug17857 VALUES (?)"); + pStmt.close(); + try { + pStmt.clearParameters(); + } catch (SQLException sqlEx) { + assertEquals("08003", sqlEx.getSQLState()); + } + + } finally { + if (pStmt != null) { + pStmt.close(); + } + } + } } Modified: branches/branch_5_1/connector-j/CHANGES =================================================================== --- branches/branch_5_1/connector-j/CHANGES 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_1/connector-j/CHANGES 2006-03-09 21:49:02 UTC (rev 5040) @@ -175,6 +175,9 @@ parameters pre-populated. Still waiting for feedback from JDBC experts group to determine what correct parameter count from getMetaData() should be, however. + + - Fixed BUG#17587 - clearParameters() on a closed prepared statement + causes NPE. 11-30-05 - Version 3.1.12 Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -600,7 +600,9 @@ * @exception SQLException * if a database access error occurs */ - public void clearParameters() throws SQLException { + public synchronized void clearParameters() throws SQLException { + checkClosed(); + for (int i = 0; i < this.parameterValues.length; i++) { this.parameterValues[i] = null; this.parameterStreams[i] = null; Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -402,7 +402,9 @@ /** * @see java.sql.PreparedStatement#clearParameters() */ - public void clearParameters() throws SQLException { + public synchronized void clearParameters() throws SQLException { + checkClosed(); + clearParametersInternal(true); } Modified: branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java =================================================================== --- branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-03-09 21:27:40 UTC (rev 5039) +++ branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-03-09 21:49:02 UTC (rev 5040) @@ -3079,4 +3079,38 @@ } } + /** + * Tests fix for BUG#17587 - clearParameters() on a closed prepared statement + * causes NPE. + * + * @throws Exception if the test fails. + */ + public void testBug17587() throws Exception { + createTable("testBug17857", "(field1 int)"); + PreparedStatement pStmt = null; + + try { + pStmt = conn.prepareStatement("INSERT INTO testBug17857 VALUES (?)"); + pStmt.close(); + try { + pStmt.clearParameters(); + } catch (SQLException sqlEx) { + assertEquals("08003", sqlEx.getSQLState()); + } + + pStmt = ((com.mysql.jdbc.Connection)conn).clientPrepareStatement("INSERT INTO testBug17857 VALUES (?)"); + pStmt.close(); + try { + pStmt.clearParameters(); + } catch (SQLException sqlEx) { + assertEquals("08003", sqlEx.getSQLState()); + } + + } finally { + if (pStmt != null) { + pStmt.close(); + } + } + } + }