apache / apache/iotdb

[Bug] findColumn throws NullPointerException instead of SQLException for an unknown column name

Offen Anfängerfreundlich
#18,250 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
6.4k
Forks
1.2k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
115

Beschreibung

### Search before asking

- [x] I searched in the [issues](https://github.com/apache/iotdb/issues) and found nothing similar.

### Version

`master` (2.0.x). The affected code is also present in released 2.0.x versions.

### Describe the bug and provide the minimal reproduce step

`IoTDBRpcDataSet.findColumn(String)` returns `columnOrdinalMap.get(columnName)` directly. When the column name is not present, `Map.get` returns `null`, which auto-unboxes to `int` and throws a `NullPointerException`. The JDBC contract (`ResultSet.findColumn`) requires a `SQLException` when the column is not found, and the sibling `findColumnNameByIndex` already guards its input and throws — the guard was simply omitted for `findColumn`.

This surfaces at the JDBC boundary (`IoTDBJDBCResultSet.findColumn`) and through `SessionDataSet.DataIterator.findColumn`, both of which delegate to the method above. The same missing guard also exists in `IoTDBJDBCDataSet.findColumn`.

Minimal reproduce step:

1. Execute any query over JDBC and obtain the `ResultSet`.
2. Call `resultSet.findColumn("a_column_name_that_is_not_in_the_result")`.
3. A raw `NullPointerException` is thrown instead of a `SQLException`.

### What did you expect to see?

`findColumn` throws a `SQLException` (at the JDBC boundary) that names the missing column, per the `ResultSet.findColumn` contract.

### What did you see instead?

A `NullPointerException`, from unboxing the `null` returned by the column-ordinal map lookup.

### Anything else?

The fix mirrors the existing `findColumnNameByIndex` guard: throw a checked `StatementExecutionException` at the rpc layer (reusing the existing `UNKNOWN_COLUMN_NAME` message), converted to `SQLException` at the JDBC boundary. I'd like to work on this and will open a PR (which also fixes the identical, currently-unused-but-public `IoTDBJDBCDataSet.findColumn`).

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne bei IoTDBRpcDataSet.findColumn und vergleiche die Methode mit der bestehenden Guard-Prüfung in findColumnNameByIndex. Verfolge anschließend die JDBC-Grenze durch IoTDBJDBCResultSet.findColumn und SessionDataSet.DataIterator.findColumn. Überprüfe auch IoTDBJDBCDataSet.findColumn; als erledigt gilt die Änderung, wenn eine unbekannte Spalte eine SQLException mit dem Namen der fehlenden Spalte statt einer NullPointerException erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
database
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
78/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.