Bug #78313 proxies not handling Object.equals(Object) calls correctly
Submitted: 3 Sep 2015 7:57 Modified: 14 Jul 2017 22:07
Reporter: Thomas Beckmann Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:5.1 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[3 Sep 2015 7:57] Thomas Beckmann
At least for the replicating driver this causes C3P0 malfunction. When using the replicating driver PreparedStatements are dynamic proxies. Since Object.equals(Object) is not dealt with but passed through, the calls become PreparedStatement.equals(Proxy) and never yield true. This means, the PreparedStatement is not equal to itself!

In C3P0 linked lists are used for keeping track of PreparedStatements. Unlike hash maps, the linked lists do not short-circuit equals calls for reference equality. As a result the remove operation on the linked list fails.

I'll contribute a guard statement protecting against the error to C3P0. The problem must be solved in MySQL driver codebase however.

How to repeat:
Instantiate the replicating driver, prepare a statement (stmt) and call stmt.equals(stmt) which should return true, but yields false!

Suggested fix:
[3 Sep 2015 8:13] Thomas Beckmann
see also https://sourceforge.net/p/c3p0/bugs/133/ and https://github.com/swaldman/c3p0/pull/59.
[1 Oct 2015 17:11] Filipe Silva
Hi Thomas,

Thank you for this bug report. Verified as described.

You have submitted a code contribution in our GitHub repository. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at http://www.oracle.com/technetwork/community/oca-486395.html
Please make sure to include your MySQL bug system user (email) in the returned form.

Thank you.
[14 Jul 2017 22:07] Daniel So
Posted by developer:
Added an entry to the Connector/J 5.1.43 changelog:

"Some JDBC proxied objects were missing the proper handling of the equals() methods, thus even comparison of one of these proxied objects to its own self with equals() yielded false. This patch introduces proper handling for the equals() method in all relevant proxies."
[29 Aug 2017 20:02] Daniel So
Posted by developer:
Added the changelog entry for Connector/J 8.0.8.