| Bug #87099 | DBMD.getProductVersion() throws NPE when Connection is closed | ||
|---|---|---|---|
| Submitted: | 17 Jul 2017 17:28 | Modified: | 6 Sep 2021 9:29 |
| Reporter: | Mark Matthews | Email Updates: | |
| Status: | Can't repeat | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) |
| Version: | 5.1.38 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[19 Jan 2018 18:29]
Filipe Silva
Posted by developer: Hi Mark, Thank you for reporting this.
[6 Sep 2021 9:29]
Alexander Soklakov
Posted by developer: This bug is not reproducible with the latest Connector/J 8.0. Connector/J 5.1 series came to EOL on Feb 9th, 2021, see https://www.mysql.com/support/eol-notice.html, so this bug will not be fixed there.

Description: Calling DatabaseMetaData.getDatabaseProductVersion() for a connection that has been closed results in a NullPointerException being thrown. Public API methods for JDBC aren't supposed to throw NullPointerExceptions, instead a SQLException with the appropriate SQLState should be thrown. The stack looks like: java.lang.NullPointerException at com.mysql.jdbc.ConnectionImpl.getServerVersion(ConnectionImpl.java:3035) at com.mysql.jdbc.DatabaseMetaData.getDatabaseProductVersion(DatabaseMetaData.java:2829) The offending code is in ConnectionImpl: public String getServerVersion() { return this.io.getServerVersion(); } (this.io is null once the connection has been closed). How to repeat: Call .getDatabaseProductVersion() on a DBMD instance that has been previously returned from Connection.getMetaData(), and then the connection is closed. Suggested fix: Any methods in DBMD that reference the connection should first check that the underlying connection hasn't been closed. (HEAD still has this bug - https://github.com/mysql/mysql-connector-j/blob/release/5.1/src/com/mysql/jdbc/ConnectionI...)