Bug #53041 Error in ConectionImpl with NoSubInterceptorWrapper
Submitted: 21 Apr 2010 21:54 Modified: 22 Apr 2010 10:36
Reporter: Jonathan Reichhold Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.1.12 OS:Any
Assigned to: Tony Bedford CPU Architecture:Any
Tags: java, jdbc, MySQL

[21 Apr 2010 21:54] Jonathan Reichhold
Description:
NoSubInterceptorWrapper is supposed to: "Wraps statement interceptors during driver startup so that they don't produce different result sets than we expect."

Looking at the implementation in the ConnectionImpl there is a bug:

    protected void unSafeStatementInterceptors() throws SQLException {

    	ArrayList unSafedStatementInterceptors = new ArrayList(this.statementInterceptors.size());

    	this.statementInterceptors = new ArrayList(this.statementInterceptors.size());

    	for (int i = 0; i < this.statementInterceptors.size(); i++) {
    		NoSubInterceptorWrapper wrappedInterceptor = (NoSubInterceptorWrapper) this.statementInterceptors.get(i);

    		unSafedStatementInterceptors.add(wrappedInterceptor.getUnderlyingInterceptor());
    	}

    	this.statementInterceptors = unSafedStatementInterceptors;
	}

Notice that the this.statementInterceptors = new ArrayList(this.statementInterceptors.size()); line is creating a new array and then iterating on it.  This is wrong.  Removal of this line would fix the method to work as intended and documented.

How to repeat:
Add an interceptor.  Verify that it isn't actually producing the result.  It is called, but the result is thrown away.  This was introduced in 5.1.11 and seems to not be tested at all.

Suggested fix:
Remove line creating new array
[21 Apr 2010 22:02] Mark Matthews
This is already fixed in the branch, and has been for awhile. The fix will ship w/ 5.1.13.
[22 Apr 2010 5:56] Tonci Grgin
Thanks Mark.
[22 Apr 2010 10:36] Tony Bedford
An entry has been added to the 5.1.13 changelog:

The method unSafeStatementInterceptors() contained an erroneous line of code, which resulted in the interceptor being called, but the result being thrown away.