Bug #71924 StatementInterceptorV2.postProcess() exceptions swallows other exceptions

Submitted: 4 Mar 2014 13:22 Modified: 4 Mar 2014 13:23
Reporter: Filipe Silva Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.29 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[4 Mar 2014 13:22] Filipe Silva
Description:
If the method StatementInterceptorV2.postProcess() throws an exception, it swallows any other that may have occurred while executing the main query.

How to repeat:
package mysql.interceptors;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import com.mysql.jdbc.ResultSetInternalMethods;
import com.mysql.jdbc.StatementInterceptorV2;

public class StatementInterceptorTest {
	private static final String CONNECTION_URL = "jdbc:mysql:///test?statementInterceptors="
			+ MyStatementInterceptor.class.getName();

	private static final String USERNAME = "myuser";
	private static final String PASSWORD = "mypass";

	public static void main(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");

		Connection conn = DriverManager.getConnection(CONNECTION_URL, USERNAME, PASSWORD);
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT c FROM t_original");

		rs.close();
		stmt.close();
		conn.close();
	}

	public static class MyStatementInterceptor implements StatementInterceptorV2 {
		public void init(com.mysql.jdbc.Connection conn, Properties props) throws SQLException {
		}

		public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement,
				com.mysql.jdbc.Connection connection) throws SQLException {
			return null;
		}

		public boolean executeTopLevelOnly() {
			return true;
		}

		public void destroy() {
		}

		public ResultSetInternalMethods postProcess(String sql, com.mysql.jdbc.Statement interceptedStatement,
				ResultSetInternalMethods originalResultSet, com.mysql.jdbc.Connection connection, int warningCount,
				boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) throws SQLException {

			return (ResultSetInternalMethods) interceptedStatement.executeQuery("SELECT c FROM t_intercepted");
		}
	}
}

Suggested fix:
Chain exceptions thrown.
[4 Mar 2014 16:23] Filipe Silva
Posted by developer:
 
Instead of the postProcess() method above, the correct code example should contain:

public ResultSetInternalMethods postProcess(String sql, com.mysql.jdbc.Statement interceptedStatement,
		ResultSetInternalMethods originalResultSet, com.mysql.jdbc.Connection connection, int warningCount,
		boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) throws SQLException {

	if (sql.contains("t_original")) {
		return (ResultSetInternalMethods) interceptedStatement.executeQuery(sql.replace("t_original", "t_intercepted"));
	}
	return originalResultSet;
}

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.