A JDBC parameter or column is addressed with index 0 or less, but they are numbered from 1

tx0/java:jdbc-index-zerodefaulterrorbug

What it finds

The parameters of a JDBC statement and the columns of a result set are numbered from 1, as the java.sql documentation says. statement.setString(0, name) and rows.getInt(0) throw an SQLException for the invalid index.

Reported is a set... call on a PreparedStatement or CallableStatement, and a get... or update... call on a ResultSet or a column method of ResultSetMetaData, whose first argument is an integer literal of 0 or less, on a variable declared with one of these types.

From the rule's source, jdbc_index_zero.rs.

Example from the rule's tests
import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException; class Users {  String load(PreparedStatement statement, ResultSet rows, String name) throws SQLException {    statement.setString(0, name);tx0 reports: JDBC indexes start at 1, so index 0    statement.setString(1, name);    String first = rows.getString(0);tx0 reports: index 0 throws    String second = rows.getString(1);    String third = rows.getString("name");    return first + second + third;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:jdbc-index-zero" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:jdbc-index-zero] reason="..."

tx0 explain tx0/java:jdbc-index-zero shows the same in the terminal. Found a false positive? Report it.