| Bug #107094 | NullPointerException when calling equals with null on MultiHostConnectionProxy | ||
|---|---|---|---|
| Submitted: | 22 Apr 2022 8:32 | Modified: | 19 Oct 12:15 |
| Reporter: | Jens Borgland | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) |
| Version: | 8.0.28 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[25 Apr 2022 10:55]
MySQL Verification Team
Hello Jens Borgland, Thank you for the report. regards, Umesh
[19 Oct 12:15]
Edward Gilmore
Posted by developer:
Added the following note to the Connector/J 9.5.0 release notes:
Calling the equals method on MultiHostConnectionProxy with a
null argument resulted in a NullPointerException.
Errors were returned similar to the following:
java.lang.NullPointerException: null

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