| Bug #118938 | DatabaseMetaDataInformationSchema#getSchemas has a bug | ||
|---|---|---|---|
| Submitted: | 4 Sep 2025 5:38 | Modified: | 4 Nov 2025 20:08 |
| Reporter: | Jin Kwon | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / J | Severity: | S1 (Critical) |
| Version: | 9.4.0 | OS: | Any |
| Assigned to: | Filipe Silva | CPU Architecture: | Any |
[5 Sep 2025 14:28]
Filipe Silva
Hi Jin Kwon, Thank you for your interest in MySQL Connector/J and for taking the time to report this issue. I have verified the issue as described.
[19 Oct 2025 16:08]
Edward Gilmore
Posted by developer: Internal. No documentation required.
[19 Oct 2025 16:10]
Edward Gilmore
Posted by developer: Closed in error
[4 Nov 2025 20:08]
Edward Gilmore
Posted by developer: Added the following note to the MySQL Connector/J 9.5.0 release notes: Added validations to DatabaseMetaDataInformationSchema#getSchemas, preventing invalid query generation and avoiding related exceptions.

Description: ``` StringBuilder query = new StringBuilder("SELECT"); query.append(" SCHEMA_NAME AS TABLE_SCHEM,"); // TABLE_SCHEM query.append(" CATALOG_NAME AS TABLE_CATALOG"); // TABLE_CATALOG query.append(" FROM INFORMATION_SCHEMA.SCHEMATA"); query.append(chooseBasedOnDatabaseTerm(() -> " WHERE FALSE", () -> dbFilter == null ? "" : StringUtils.hasWildcards(dbFilter) ? " WHERE SCHEMA_NAME LIKE ?" : " WHERE SCHEMA_NAME = ?")); try (PreparedStatement pStmt = prepareMetaDataSafeStatement(query.toString())) { if (dbFilter != null) { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< pStmt.setString(1, dbFilter); // <<<<<<<<<<<<<<<<<<<<< } ResultSet rs = executeMetadataQuery(pStmt); ((com.mysql.cj.jdbc.result.ResultSetInternalMethods) rs).getColumnDefinition().setFields(createSchemasFields()); return rs; } ``` When the `chooseBaseOnDatabaseTerm` evaluates ` WHERE FALSE`, The following if statement still checks `doFilter != null`, and throws ``` Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). ``` How to repeat: Make a case which evaluates ` WHERE FALSE`.