{"record":{"id":"7bbd20d186d15696","repo":"apache/shardingsphere","slug":"first-7bbd20","errorCode":null,"errorMessage":"first","messagePattern":"first","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java","lineNumber":70,"sourceCode":"    \n    @Override\n    public boolean isLast() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"isLast\");\n    }\n    \n    @Override\n    public void beforeFirst() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"beforeFirst\");\n    }\n    \n    @Override\n    public void afterLast() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"afterLast\");\n    }\n    \n    @Override\n    public boolean first() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"first\");\n    }\n    \n    @Override\n    public boolean last() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"last\");\n    }\n    \n    @Override\n    public boolean absolute(final int row) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"absolute\");\n    }\n    \n    @Override\n    public boolean relative(final int rows) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"relative\");\n    }\n    \n    @Override","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java#L52-L88","documentation":"The SQL Federation ResultSet does not implement first(), the JDBC cursor method that moves the cursor to the first row. AbstractUnsupportedOperationSQLFederationResultSet intentionally throws SQLFeatureNotSupportedException for all scroll-position methods because federation results are forward-only streams produced by the federation engine. Any invocation of first() fails immediately.","triggerScenarios":"Calling rs.first() on a ResultSet returned by a statement executed with SQL Federation enabled (cross-database or push-down query rewritten by the federation optimizer), typically to reset iteration or read row 1 again after partial iteration.","commonSituations":"Application code that restarts result-set iteration with first() (common in legacy JDBC DAOs); frameworks that call first() to check emptiness; migrating an app from a plain MySQL/PostgreSQL driver (which supports scrollable cursors) to ShardingSphere with federation turned on.","solutions":["Replace the first() reset pattern with a single forward loop, or re-execute the query if a second pass is needed","To test emptiness, call rs.next() once instead of first()","If random re-positioning is mandatory, populate a client-side scrollable RowSet (CachedRowSet) from the federated ResultSet and call first() on that"],"exampleFix":"// before\nif (rs.first()) { doSomething(rs); }\n\n// after\nif (rs.next()) { doSomething(rs); }","handlingStrategy":"try-catch","validationCode":"if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {\n    // first() unsupported: use rs.next() to test/reach the first row\n}","typeGuard":"private boolean canRewind(final ResultSet rs) throws SQLException {\n    return rs.getType() != ResultSet.TYPE_FORWARD_ONLY;\n}","tryCatchPattern":"try {\n    ok = rs.first();\n} catch (final SQLFeatureNotSupportedException e) {\n    ok = rs.next(); // forward-only fallback\n}","preventionTips":["Prefer rs.next() for emptiness checks over rs.first()","Document federation datasources as forward-only in team coding guides","Wrap shared DAO code with a scroll-capability check via rs.getType()"],"tags":["jdbc","resultset","sql-federation","cursor","shardingsphere"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}