{"record":{"id":"f53edbdef38bfb0c","repo":"prestodb/presto","slug":"invalid-column-index-f53edb","errorCode":null,"errorMessage":"Invalid column index: ","messagePattern":"Invalid column index: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSetMetaData.java","lineNumber":258,"sourceCode":"    {\n        if (isWrapperFor(iface)) {\n            return (T) this;\n        }\n        throw new SQLException(\"No wrapper for \" + iface);\n    }\n\n    @Override\n    public boolean isWrapperFor(Class<?> iface)\n            throws SQLException\n    {\n        return iface.isInstance(this);\n    }\n\n    private ColumnInfo column(int column)\n            throws SQLException\n    {\n        if ((column <= 0) || (column > columnInfo.size())) {\n            throw new SQLException(\"Invalid column index: \" + column);\n        }\n        return columnInfo.get(column - 1);\n    }\n}\n","sourceCodeStart":240,"sourceCodeEnd":263,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSetMetaData.java#L240-L263","documentation":"Private bounds-check helper: any metadata getter that takes a column index first calls column(), which throws this SQLException when the index is less than 1 or greater than the number of columns. JDBC column indexes are 1-based, so index 0 or an index past the last column is invalid.","triggerScenarios":"Calling isCurrency, nullable, isSigned, getColumnDisplaySize, getColumnLabel, or getColumnName with index 0, a negative value, or an index > columnInfo.size() (e.g. iterating 1..count instead of 1..=count mistakes).","commonSituations":"Loop bounds bugs (for i = 0 instead of 1); assuming 0-based indexes like arrays; reading a column that no longer exists after the query changed; metadata from one ResultSet applied to another.","solutions":["Use 1-based indexes: valid range is 1 to ResultSetMetaData.getColumnCount()","Validate against getColumnCount() before calling metadata getters","Fix loop bounds in metadata-iteration code"],"exampleFix":"// before\nfor (int i = 0; i <= meta.getColumnCount(); i++) { meta.getColumnName(i); }\n// after\nfor (int i = 1; i <= meta.getColumnCount(); i++) { meta.getColumnName(i); }","handlingStrategy":"validation","validationCode":"int count = meta.getColumnCount();\nif (column < 1 || column > count) {\n    throw new IllegalArgumentException(\"Column index \" + column + \" out of range 1..\" + count);\n}","typeGuard":"boolean validColumn = (column >= 1) && (column <= meta.getColumnCount());","tryCatchPattern":"try {\n    String name = meta.getColumnName(col);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid column index\")) {\n        throw new IllegalArgumentException(\"Bad column \" + col + \", valid range 1..\" + meta.getColumnCount(), e);\n    } else { throw e; }\n}","preventionTips":["Remember JDBC column indexes are 1-based","Always bound loops with i <= meta.getColumnCount()","Verify column positions after any change to the SELECT list"],"tags":["jdbc","metadata","index-out-of-range"],"backgroundTag":"jdbc-invalid-column-index","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}