{"record":{"id":"33591f83086241f7","repo":"apache/shardingsphere","slug":"20","errorCode":"20","errorMessage":"Column index '%d' is out of range.","messagePattern":"Column index '(.+?)' is out of range\\.","errorType":"exception","errorClass":"ColumnIndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java","lineNumber":428,"sourceCode":"    @Override\n    public void setFetchSize(final int rows) throws SQLException {\n        resultSet.setFetchSize(rows);\n    }\n    \n    @Override\n    public boolean isClosed() {\n        return closed;\n    }\n    \n    private void checkClosed() throws SQLException {\n        if (closed) {\n            throw new ResultSetClosedException().toSQLException();\n        }\n    }\n    \n    private void checkColumnIndex(final int columnIndex) throws SQLException {\n        if (columnIndex < 1 || columnIndex > resultSetMetaData.getColumnCount()) {\n            throw new ColumnIndexOutOfRangeException(columnIndex).toSQLException();\n        }\n    }\n    \n    @EqualsAndHashCode\n    private static final class DatabaseMetaDataObject {\n        \n        private final List<Object> objects;\n        \n        private DatabaseMetaDataObject(final int columnCount) {\n            objects = new ArrayList<>(columnCount);\n        }\n        \n        public void addObject(final Object object) {\n            objects.add(object);\n        }\n        \n        public Object getObject(final int index) {\n            return objects.get(index - 1);","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java#L410-L446","documentation":"ColumnIndexOutOfRangeException (code 20) thrown by DatabaseMetaDataResultSet.checkColumnIndex when columnIndex < 1 or > resultSetMetaData.getColumnCount(). It is a plain bounds check on the 1-based index into the metadata result set's columns.","triggerScenarios":"Calling getObject(int)/getXxx(int) on a DatabaseMetaData ResultSet with index 0, a negative index, or an index beyond the number of columns that metadata method returns.","commonSituations":"Looping with 0-based indices over 1-based JDBC columns; assuming a metadata result set has more columns than it does (driver-specific extras); ported code from another driver with a wider metadata layout.","solutions":["Use 1-based indices: iterate from 1 to rs.getMetaData().getColumnCount() inclusive.","Prefer column labels over indices for metadata result sets.","Print the column count first when unsure of the layout."],"exampleFix":"// before\nfor (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { rs.getString(i); }\n// after\nfor (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { rs.getString(i); }","handlingStrategy":"validation","validationCode":"int cols = rs.getMetaData().getColumnCount();\nif (index < 1 || index > cols) throw new IndexOutOfBoundsException(\"use 1..\" + cols);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always loop 1..getColumnCount() inclusive","Prefer labels over indices","Remember JDBC is 1-based"],"tags":["jdbc","resultset","column-index","bounds"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}