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);
}