Skip to content

Missing Nullability annotation on JdbcTemplate.batchUpdate #37011

Description

@alshain

From Kotlin, calling JdbcTemplate.batchUpdate with an array containing nulls is impossible because of a missing nullability annotation:

jdbcTemplate.batchUpdate(
  """
  INSERT INTO "my_table" ("non_null", "can_be_null") VALUES (?, ?)
  """,
  listOf(
    arrayOf<Any?>(
      "non-null",
      null,
    )
  )
)

Error:

None of the following candidates is applicable:
<SNIP>
                                                             vvvvvvvvv
fun batchUpdate(sql: String, batchArgs: (Mutable)List<Array<(out) Any>>): IntArray:
Argument type mismatch: actual type is 'List<Array<Any?>>', but '(Mutable)List<Array<(out) Any>>' was expected.

Proposed solution

Change to List<@Nullable Object[]> here:

@Override
public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException {
return batchUpdate(sql, batchArgs, new int[0]);
}
@Override
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException {
if (batchArgs.isEmpty()) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions