{"record":{"id":"26d9400851a02660","repo":"tursodatabase/turso","slug":"index-out-of-bound","errorCode":null,"errorMessage":"Index out of bound: {}","messagePattern":"Index out of bound: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java","lineNumber":1312,"sourceCode":"\n  @Override\n  public int getColumnDisplaySize(int column) throws SQLException {\n    return Integer.MAX_VALUE;\n  }\n\n  @Override\n  public String getColumnLabel(int column) throws SQLException {\n    // TODO: should consider \"AS\" keyword\n    return getColumnName(column);\n  }\n\n  @Override\n  public String getColumnName(int column) throws SQLException {\n    if (column > 0 && column <= resultSet.getColumnNames().length) {\n      return resultSet.getColumnNames()[column - 1];\n    }\n\n    throw new SQLException(\"Index out of bound: \" + column);\n  }\n\n  @Override\n  public String getSchemaName(int column) throws SQLException {\n    throw new UnsupportedOperationException(\"not implemented\");\n  }\n\n  @Override\n  public int getPrecision(int column) throws SQLException {\n    throw new UnsupportedOperationException(\"not implemented\");\n  }\n\n  @Override\n  public int getScale(int column) throws SQLException {\n    throw new UnsupportedOperationException(\"not implemented\");\n  }\n\n  @Override","sourceCodeStart":1294,"sourceCodeEnd":1330,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java#L1294-L1330","documentation":"getColumnName(int) validates the 1-based column index against the underlying result set (`resultSet.getColumnNames().length`) and throws SQLException(\"Index out of bound: \" + column) when column <= 0 or column > column count. getColumnLabel delegates to this method, so label lookups fail identically. getColumnCount() is implemented and returns the same length, so callers can pre-validate.","triggerScenarios":"Calling getColumnName or getColumnLabel with 0 (the classic 0-based array index bug), a negative value, or an index larger than the SELECT's column list, e.g. a hardcoded position left over after the query was rewritten to return fewer columns, or a position taken from a different statement's result set.","commonSituations":"Porting loops that iterate columns from 0; table renderers and metadata walkers using array indices directly; cached column positions drifting out of sync with an edited SELECT; findColumn fallback code that falls back to positions from another query.","solutions":["Use 1-based indexes for all JDBC column access","Loop columns with `for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)`","Resolve positions via rs.findColumn(name) on the current result set instead of hardcoding them","If the index is external input, validate 1..getColumnCount() before calling"],"exampleFix":"// before\nfor (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {\n  String name = rs.getMetaData().getColumnName(i); // throws for i == 0\n}\n\n// after\nResultSetMetaData md = rs.getMetaData();\nfor (int i = 1; i <= md.getColumnCount(); i++) {\n  String name = md.getColumnName(i);\n}","handlingStrategy":"validation","validationCode":"ResultSetMetaData md = rs.getMetaData();\nint n = md.getColumnCount();\nif (column < 1 || column > n) {\n  throw new IllegalArgumentException(\"column must be in 1..\" + n + \", got \" + column);\n}\nString name = md.getColumnName(column);","typeGuard":null,"tryCatchPattern":"try {\n  String name = rs.getMetaData().getColumnName(column);\n} catch (SQLException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Index out of bound\")) {\n    // bad index: recompute from findColumn or fail with context\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always loop JDBC columns from 1 through getColumnCount() inclusive","Prefer rs.findColumn(\"name\") over hardcoded positions","After editing a SELECT, recheck every hardcoded column position used against it"],"tags":["java","jdbc","turso","column-index","off-by-one","validation"],"backgroundTag":"index-out-of-bounds","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}