Skip to content

Fix JdbcOperations Kotlin extensions #35846

@agrounds

Description

@agrounds

Library: spring-jdbc v7.0.0

Bug description

The JdbcOperations.queryForList(sql: String, args: Array<out Any>) Kotlin extension function incorrectly passes the args array as the first, non-spread, argument to this Java method:

// from org.springframework.jdbc.core.JdbcOperations
List<Map<String, @Nullable Object>> queryForList(
    String sql,
    Class<T> elementType,
    @Nullable Object @Nullable ... args
) throws DataAccessException;

The effect is that the array args in the extension function ends up getting passed as the first and only rest parameter of the Java method, so in the Java code, args is an array of an array of values.

Example

In Kotlin code:

// jdbc is a JdbcTemplate
val results = jdbc.queryForList<String>(
    "SELECT id FROM users WHERE email = ?",
    arrayOf("somebody@domain.com"),
)

The JdbcTemplate ends up getting called with

queryForList(
    "SELECT id FROM users WHERE email = ?",
    String.class,
    new Object[] { 
        new String[] {"somebody@domain.com" }
    }
);

and finally, the DB (in my case, postgresql) throws an error, e.g.:

org.postgresql.util.PSQLException: ERROR: operator does not exist: text = character varying[]

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)theme: kotlinAn issue related to Kotlin supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions