Skip to content

DuckDBArrayResultSet reports wasNull wrong on scalar types (i.e. int, double). #833

Closed

Description

@michael-simons

DuckDBArrayResultSet uses accessors of DuckDBVector to retrieve values. getInt and others however return a scalar type, i.e. int getInt(int idx) throws SQLException. The assignment to wasNull in org.duckdb.DuckDBArrayResultSet#getValue checking whether value was null will always return false, hence wasNull() will return the wrong result.

I tested 1.5.5.0 only, but expect similar results with older version and on all other scalar types:

Reproducer:

curl -O https://repo1.maven.org/maven2/org/duckdb/duckdb_jdbc/1.5.5.0/duckdb_jdbc-1.5.5.0.jar 
cat <<- 'EOF' > Application.java
import java.sql.DriverManager;
import java.sql.SQLException;

void main() throws SQLException {
        try (var connection = DriverManager.getConnection("jdbc:duckdb:");
             var stmt = connection.createStatement();
             var rs = stmt.executeQuery("SELECT [1, null] AS a");
        ) {
                while (rs.next()) {
                        var a = rs.getArray("a");
                        var inner = a.getResultSet();
                        int i = 0;

                        inner.next();
                        var val = inner.getInt(2);
                        assert val == 1;
                        inner.next();
                        val = inner.getInt(2);
                        assert val == 0;
                        assert inner.wasNull() : "Array result did wrongly reported null state";

                }
        }
}
EOF
java --enable-native-access=ALL-UNNAMED -ea -cp duckdb_jdbc-1.5.5.0.jar Application.java
rm Application.java

Will yield

Exception in thread "main" java.lang.AssertionError: Array result did wrongly reported null state
	at Application.main(Application.java:20)

I use

java -version
openjdk version "26" 2026-03-17
OpenJDK Runtime Environment Zulu26.28+59-CA (build 26+35)
OpenJDK 64-Bit Server VM Zulu26.28+59-CA (build 26+35, mixed mode, sharing)

Activity

  1. added a commit that references this issue on Aug 24, 2026
    026c99d
  2. added a commit that references this issue on Aug 24, 2026
    f4e6c80
  3. staticlibs commented on Aug 25, 2026

    @staticlibs
    Member

    Hi, thanks for the report! I added a fix in #839, snapshot with this fix (compatible with 1.5.5 extensions):

    <dependency>
        <groupId>org.duckdb</groupId>
        <artifactId>duckdb_jdbc</artifactId>
        <version>1.5.5.2-dev-f4e6c80</version>
    </dependency>
    <repository>
        <id>duckdb</id>
        <url>https://duckdb-staging.duckdb.org/duckdb/duckdb-java/maven/</url>
    </repository>
  4. michael-simons commented on Aug 25, 2026

    @michael-simons
    Author

    Very nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions