Skip to content

Fix JdbcOperations Kotlin extensions #35846

Closed

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[]

Activity

  1. added
    theme: kotlinAn issue related to Kotlin support
    in: dataIssues in data modules (jdbc, orm, oxm, tx)
    and removed on Nov 18, 2025
  2. self-assigned this
    on Nov 18, 2025
  3. added this to the 7.0.1 milestone on Nov 18, 2025
  4. changed the title [-]Kotlin JdbcOperations.queryForList extension fails to spread array of query args[/-] [+]Fix `RestOperations` Kotlin extensions[/+] on Nov 19, 2025
  5. changed the title [-]Fix `RestOperations` Kotlin extensions[/-] [+]Fix `JdbcOperations ` Kotlin extensions[/+] on Nov 19, 2025
  6. added 3 commits that reference this issue on Nov 19, 2025
    23f0cfb
    1d1851f
  7. sdeleuze commented on Nov 19, 2025

    @sdeleuze
    Contributor

    @agrounds Thanks for catching this, I did a more comprehensive update as various things were broken or inconsistent.

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

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

    ⌂ 换网址