{"record":{"id":"e2a145d4597d8e80","repo":"apache/shardingsphere","slug":"getwarnings","errorCode":null,"errorMessage":"getWarnings","messagePattern":"getWarnings","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java","lineNumber":71,"sourceCode":"    \n    @Override\n    public final InputStream getUnicodeStream(final String columnLabel) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getUnicodeStream\");\n    }\n    \n    @Override\n    public final InputStream getBinaryStream(final int columnIndex) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getBinaryStream\");\n    }\n    \n    @Override\n    public final InputStream getBinaryStream(final String columnLabel) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getBinaryStream\");\n    }\n    \n    @Override\n    public final SQLWarning getWarnings() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getWarnings\");\n    }\n    \n    @Override\n    public final void clearWarnings() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"clearWarnings\");\n    }\n    \n    @Override\n    public final Reader getCharacterStream(final int columnIndex) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getCharacterStream\");\n    }\n    \n    @Override\n    public final Reader getCharacterStream(final String columnLabel) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getCharacterStream\");\n    }\n    \n    @Override","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java#L53-L89","documentation":"java.sql.SQLFeatureNotSupportedException thrown by the Apache ShardingSphere JDBC driver when ResultSet.getWarnings() is called on a DatabaseMetaData result set. Metadata calls such as Connection.getMetaData().getTables()/getColumns()/getIndexInfo()/getPrimaryKeys() on a jdbc:shardingsphere: URL return a synthesized DatabaseMetaDataResultSet that buffers every row as plain Java objects, so only scalar getters (getString, getInt, getBytes, single-arg getDate/getTime/getTimestamp, ...) are implemented. getWarnings() is declared final in AbstractUnsupportedDatabaseMetaDataResultSet and always throws, so this is a permanent, intentional limitation, not a version bug. Because rows are copied into an in-memory iterator, the metadata result set never accumulates warnings and the whole warnings API is stubbed out.","triggerScenarios":"Calling getWarnings() on the ResultSet returned by ShardingSphereDatabaseMetaData, e.g. connection.getMetaData().getTables(null, null, \"%\", new String[]{\"TABLE\"}\") followed by rs.getWarnings()) where connection was opened with the org.apache.shardingsphere.driver JDBC URL (jdbc:shardingsphere:classpath:sharding.yaml or jdbc:shardingsphere:...). Both the int-columnIndex and String-columnLabel overloads of every listed getter throw; the methods are final so no subclass can override them.","commonSituations":"Code that ran unchanged against the native MySQL/PostgreSQL/OpenGauss driver and is repointed to the ShardingSphere driver URL, so the same metadata loop now hits the stubbed getter; generic schema tooling that enumerates JDBC metadata with feature-rich getters (DBeaver, Squirrel SQL, Liquibase/Hibernate/Flyway schema validators, code generators, DBDiff tools); hand-written metadata loops that defensively call getWarnings()/clearWarnings() or use the Calendar overloads to pin a timezone. ","solutions":["Remove the rs.getWarnings() call: metadata result sets never produce warnings, so skipping it changes nothing.","If you cannot remove it (library code), wrap the call in a catch (SQLFeatureNotSupportedException) and ignore.","If warning handling is genuinely needed for real queries, call getWarnings()/clearWarnings() on ResultSets from Statement.executeQuery, not on DatabaseMetaData result sets.","Do not wait for a driver upgrade: the throw is final and by design."],"exampleFix":"// before - throws SQLFeatureNotSupportedException on ShardingSphere metadata result sets\nSQLWarning w = metaDataRs.getWarnings();\nmetaDataRs.clearWarnings();\n\n// after - the metadata result set never carries warnings; just remove the calls\n// (or guard them when the same loop also runs on other drivers)\ntry {\n    metaDataRs.clearWarnings();\n} catch (final SQLFeatureNotSupportedException ignored) {\n    // ShardingSphere metadata result sets do not support warnings\n}","handlingStrategy":"try-catch","validationCode":"// Run BEFORE using exotic getters: detect a ShardingSphere-synthesized metadata ResultSet\nstatic boolean isShardingSphereMetaDataResultSet(final ResultSet rs) {\n    return rs != null && \"org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet\"\n            .equals(rs.getClass().getName());\n}\n\nstatic boolean supportsMetaDataGetter(final Connection c) throws SQLException {\n    // jdbc:shardingsphere: URLs return the synthesized metadata result set\n    return c != null && !c.getMetaData().getURL().startsWith(\"jdbc:shardingsphere:\");\n}","typeGuard":"private static boolean isUnsupportedMetaDataResultSet(final ResultSet rs) {\n    return rs != null && rs.getClass().getName().startsWith(\"org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet\");\n}","tryCatchPattern":"try {\n    return rs.getWarnings();\n} catch (final SQLFeatureNotSupportedException e) {\n    // ShardingSphere metadata result sets: fall back to the implemented scalar getter\n    // metadata result sets never carry warnings - nothing to do\n}","preventionTips":["Never assume a JDBC driver implements every ResultSet getter; DatabaseMetaData results are the most commonly stubbed surface.","When adding ShardingSphere in front of an existing datasource, smoke-test the metadata paths your frameworks use (getTables/getColumns loops) before shipping.","Prefer the simplest getter (getString/getObject/getBytes) and convert in application code; it is portable across drivers.","Treat SQLFeatureNotSupportedException (an SQLException subclass) as a signal about capability, not a transient failure - never retry it.","Keep getWarnings()/clearWarnings() calls out of generic metadata loops; many pooling/sharding wrappers do not forward them."],"tags":["jdbc","shardingsphere","database-metadata","warnings"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}