{"record":{"id":"ffcf0d7462744399","repo":"apache/shardingsphere","slug":"s-cannot-be-unwrapped-as-s","errorCode":null,"errorMessage":"`%s` cannot be unwrapped as `%s`","messagePattern":"`(.+?)` cannot be unwrapped as `(.+?)`","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/raw/metadata/RawResultSetMetaData.java","lineNumber":208,"sourceCode":"                return String.class.getName();\n            default:\n                return Object.class.getName();\n        }\n    }\n    \n    private RawQueryResultColumnMetaData getColumnMetaData(final int column) throws SQLException {\n        if (column < 1 || column > columns.size()) {\n            throw new SQLException(String.format(\"Column index out of range: %s\", column));\n        }\n        return columns.get(column - 1);\n    }\n    \n    @Override\n    public <T> T unwrap(final Class<T> iface) throws SQLException {\n        if (isWrapperFor(iface)) {\n            return iface.cast(this);\n        }\n        throw new SQLFeatureNotSupportedException(String.format(\"`%s` cannot be unwrapped as `%s`\", getClass().getName(), iface.getName()));\n    }\n    \n    @Override\n    public boolean isWrapperFor(final Class<?> iface) {\n        return iface.isInstance(this);\n    }\n}\n","sourceCodeStart":190,"sourceCodeEnd":216,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/raw/metadata/RawResultSetMetaData.java#L190-L216","documentation":"RawResultSetMetaData implements the standard JDBC Wrapper contract minimally: unwrap(iface) succeeds only when iface.isInstance(this) — i.e. only RawResultSetMetaData itself or its supertypes. Requesting any other interface (JDBC4ResultSetMetaData, driver-specific metadata, etc.) throws SQLFeatureNotSupportedException with the class names formatted into the message. Raw metadata simply does not wrap any richer implementation.","triggerScenarios":"Calling resultSet.getMetaData().unwrap(org.postgresql.jdbc.PgResultSetMetaData.class) or unwrap(com.mysql.cj.jdbc.result.ResultSetMetaData.class) through ShardingSphere; generic framework code that tries unwrap(X) before falling back, where X is never the raw metadata class.","commonSituations":"Code migrated from a direct driver connection where unwrap of the driver metadata type worked; Spring/JDBC helper libraries probing for vendor-specific metadata to read vendor columns; tests asserting vendor metadata behavior through the ShardingSphere layer.","solutions":["Call isWrapperFor(iface) first and skip the vendor-specific path when it returns false.","Do vendor-specific metadata access on a connection that bypasses ShardingSphere, or accept the generic metadata interface only.","Replace unwrap-based feature detection with SQL-level capability checks (DatabaseMetaData) that ShardingSphere forwards."],"exampleFix":"// before\nPgResultSetMetaData md = resultSet.getMetaData().unwrap(PgResultSetMetaData.class);\n\n// after\nResultSetMetaData md = resultSet.getMetaData();\nif (md.isWrapperFor(PgResultSetMetaData.class)) {\n    // vendor path on a direct driver connection only\n} else {\n    // generic path: md.getColumnName(i), md.getColumnType(i), ...\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"if (metaData.isWrapperFor(PgResultSetMetaData.class)) { ... } // only then unwrap","tryCatchPattern":"try { return metaData.unwrap(target); } catch (SQLFeatureNotSupportedException e) { /* fall back to generic ResultSetMetaData APIs */ }","preventionTips":["Call isWrapperFor before unwrap — standard Wrapper-contract hygiene.","Keep vendor-specific metadata access on direct driver connections."],"tags":["jdbc","metadata","wrapper","unwrap"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}