Bug #107094 NullPointerException when calling equals with null on MultiHostConnectionProxy
Submitted: 22 Apr 2022 8:32 Modified: 25 Apr 2022 10:55
Reporter: Jens Borgland Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.28 OS:Any
Assigned to: CPU Architecture:Any

[22 Apr 2022 8:32] Jens Borgland
Description:
Calling equals() on MultiHostConnectionProxy with null as argument (passing that directly obviously makes no sense, but passing an argument that may be null does) results in a NullPointerException due to the driver doing this (reversing the order of the comparison, without a null-check):

        if (METHOD_EQUALS.equals(methodName)) {
            // Let args[0] "unwrap" to its InvocationHandler if it is a proxy.
            return args[0].equals(this);
        }

Stack trace snippet:
java.lang.NullPointerException: null
	at com.mysql.cj.jdbc.ha.MultiHostConnectionProxy.invoke(MultiHostConnectionProxy.java:477) ~[mysql-connector-java.jar:8.0.28]
	at com.sun.proxy.$Proxy240.equals(Unknown Source) ~[?:?]

How to repeat:
1. Create a connection using failover (https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-config-failover.html).

2. Call equals(), with null as argument (connection.equals(null)).

Suggested fix:
Perhaps something like this:

        if (METHOD_EQUALS.equals(methodName)) {
            if (args[0] == null) {
                return false;
            }

            // Let args[0] "unwrap" to its InvocationHandler if it is a proxy.
            return args[0].equals(this);
        }
[25 Apr 2022 10:55] MySQL Verification Team
Hello Jens Borgland,

Thank you for the report.

regards,
Umesh