{"record":{"id":"0d6e5e6df6571582","repo":"apache/shardingsphere","slug":"afterlast-0d6e5e","errorCode":null,"errorMessage":"afterLast","messagePattern":"afterLast","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java","lineNumber":65,"sourceCode":"    \n    @Override\n    public boolean isFirst() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"isFirst\");\n    }\n    \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","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedOperationSQLFederationResultSet.java#L47-L83","documentation":"The ShardingSphere SQL Federation forward-only ResultSet implementation does not support the cursor-control method afterLast(). This abstract class deliberately overrides JDBC ResultSet methods that require a scroll-sensitive cursor with a throw of SQLFeatureNotSupportedException, because federated query results are streamed once through the federation engine. Calling afterLast() on a federation ResultSet triggers the exception unconditionally.","triggerScenarios":"Calling java.sql.ResultSet.afterLast() on a ResultSet produced by a SQL Federation (federated query) statement, e.g. rs.afterLast() while iterating results of a cross-database federated SELECT executed through ShardingSphere Proxy or JDBC in federation mode.","commonSituations":"Reusing ORM or reporting code that navigates result sets backwards (e.g. iterating in reverse with afterLast()/previous()) against a ShardingSphere federation data source; enabling sql-federation for cross-shard queries and pointing existing scroll-sensitive application code at it; MyBatis or JasperReports-style row visitors that call afterLast to detect row counts.","solutions":["Remove the afterLast() call and rely on forward-only iteration (next()) over the federated ResultSet","If backward scrolling is required, fetch all rows into a scrollable cache first: e.g. copy rows into a org.apache.shardingsphere.sqlfederation.resultset or a client-side RowSet with TYPE_SCROLL_INSENSITIVE (new CachedRowSetImpl() and populate(rs)) and scroll that","Rewrite the query so navigation is unnecessary (ORDER BY DESC instead of reverse iteration), or execute the query outside federation mode against a single shard"],"exampleFix":"// before\nResultSet rs = stmt.executeQuery(federatedSql);\nrs.afterLast();\nwhile (rs.previous()) { ... }\n\n// after\nResultSet rs = stmt.executeQuery(federatedSql);\nwhile (rs.next()) { ... }","handlingStrategy":"try-catch","validationCode":"int type = rs.getType();\nif (type == ResultSet.TYPE_FORWARD_ONLY) {\n    // afterLast() will throw SQLFeatureNotSupportedException on federation result sets\n}","typeGuard":"private boolean supportsBackwardScroll(final ResultSet rs) throws SQLException {\n    return rs.getType() != ResultSet.TYPE_FORWARD_ONLY;\n}","tryCatchPattern":"try {\n    rs.afterLast();\n} catch (final SQLFeatureNotSupportedException e) {\n    // forward-only federation result: iterate with next() instead\n    LOGGER.debug(\"scroll unsupported, falling back to forward iteration\", e);\n}","preventionTips":["Grep for afterLast|previous|beforeFirst before enabling sql-federation","Treat all federation ResultSets as TYPE_FORWARD_ONLY","Keep iteration utilities single-direction by default"],"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"}