Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16517

Kotlin compile error with JdbcOperations Extensions with variable arguments

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: 5.0.4
    • Fix Version/s: None
    • Component/s: Data:JDBC
    • Labels:
    • Last commented by a User:
      true

      Description

      Hi I'm testing out Kotlin 1.2.21 in a small Spring Boot 2 SNAPSHOT application on JDK 9.0.4 and am encountering the following (unexpected) compilation error:

      Compilation failure: 
      [ERROR] /Users/steadykeith/IdeaProjects/change/src/main/kotlin/org/steadytown/change/ChangeApplication.kt:[24,53] None of the following functions can be called with the arguments supplied: 
      [ERROR] public final fun query(p0: String!, @Nullable p1: ((PreparedStatement!) -> Unit)!, p2: ((ResultSet!) -> Unit)!): Unit defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] @Nullable public final fun <T : Any!> query(p0: String!, @Nullable p1: ((PreparedStatement!) -> Unit)!, p2: ((ResultSet!) -> Collection<Person>!)!): Collection<Person>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public final fun <T : Any!> query(p0: String!, @Nullable p1: ((PreparedStatement!) -> Unit)!, p2: ((ResultSet!, Int) -> Person!)!): (Mutable)List<Person!>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public final fun query(p0: String!, p1: ((ResultSet!) -> Unit)!, @Nullable p2: Array<(out) Any!>!): Unit defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] @Nullable public final fun <T : Any!> query(p0: String!, p1: ((ResultSet!) -> Collection<Person>!)!, @Nullable p2: Array<(out) Any!>!): Collection<Person>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public final fun <T : Any!> query(p0: String!, p1: ((ResultSet!, Int) -> Person!)!, @Nullable p2: Array<(out) Any!>!): (Mutable)List<Person!>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public final fun query(p0: String!, p1: Array<(out) Any!>!, p2: ((ResultSet!) -> Unit)!): Unit defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] @Nullable public final fun <T : Any!> query(p0: String!, p1: Array<(out) Any!>!, p2: ((ResultSet!) -> Collection<Person>!)!): Collection<Person>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public final fun <T : Any!> query(p0: String!, p1: Array<(out) Any!>!, p2: ((ResultSet!, Int) -> Person!)!): (Mutable)List<Person!>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] @Nullable public abstract fun <T : Any!> query(p0: String!, p1: Array<(out) Any!>!, p2: ResultSetExtractor<Collection<Person>!>!): Collection<Person>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public abstract fun query(p0: String!, p1: Array<(out) Any!>!, p2: RowCallbackHandler!): Unit defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public abstract fun <T : Any!> query(p0: String!, p1: Array<(out) Any!>!, p2: RowMapper<Person!>!): (Mutable)List<Person!>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] @Nullable public abstract fun <T : Any!> query(p0: String!, @Nullable p1: PreparedStatementSetter!, p2: ResultSetExtractor<Collection<Person>!>!): Collection<Person>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public abstract fun query(p0: String!, @Nullable p1: PreparedStatementSetter!, p2: RowCallbackHandler!): Unit defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] public abstract fun <T : Any!> query(p0: String!, @Nullable p1: PreparedStatementSetter!, p2: RowMapper<Person!>!): (Mutable)List<Person!>! defined in org.springframework.jdbc.core.JdbcOperations
      [ERROR] /Users/steadykeith/IdeaProjects/change/src/main/kotlin/org/steadytown/change/ChangeApplication.kt:[24,113] Cannot infer a type for this parameter. Please specify it explicitly.
      [ERROR] /Users/steadykeith/IdeaProjects/change/src/main/kotlin/org/steadytown/change/ChangeApplication.kt:[24,117] Cannot infer a type for this parameter. Please specify it explicitly.
      

      The code that is failing to compile, both in an IDE and when separately compiled using Maven, is:

          fun find(name: String): Collection<Person> = db.query("select * from PERSONS where FIRST_NAME = ?", name) { rs, _ ->
              Person(rs.getString("FIRST_NAME"), rs.getString("LAST_NAME"), rs.getDate("BIRTH_DATE").toLocalDate())
          }
      

      The following workaround (converting the argument to a single Object array parameter using arrayOf(...)) fixes the error:

      fun find(name: String): Collection<Person> = db.query("select * from PERSONS where FIRST_NAME = ?", arrayOf(name)) { rs, _ ->
              Person(rs.getString("FIRST_NAME"), rs.getString("LAST_NAME"), rs.getDate("BIRTH_DATE").toLocalDate())
          }
      

      What's really strange is I see Spring Framework's JdbcOperationsExtensionsTests.kt that cover this feature and presume they compile and run fine--however, the above similar code still fails, and even copying some of the test code into my environmental also fails with a similar compilation error.

      I apologize if I'm missing something obvious, or if something basic is wrong with my environment, but I'am really at a loss at why this compilation error is occurring against Spring JDBC 5.0.4. Since this seems to be a fairly new feature, I figured I'd report it. Thanks! Keith

        Attachments

          Activity

            People

            Assignee:
            sdeleuze S├ębastien Deleuze
            Reporter:
            kdonald Keith Donald
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 19 weeks, 5 days ago