Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newly added TransactionOperations.execute(Runnable) breaks existing Kotlin code #23724

Closed
dittos opened this issue Sep 28, 2019 · 0 comments
Closed
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: regression A bug that is also a regression
Milestone

Comments

@dittos
Copy link

dittos commented Sep 28, 2019

Affects: 5.2.0.RC1+


2c33c11 / #23250 added the new TransactionOperations.execute(Runnable) method for Java lambda usage without return value.

However it breaks existing Kotlin code using TransactionTemplate with return values:

val result = transactionTemplate.execute {
  ...
  1
}
// result becomes Unit type, which used to be Int? type

This happens because Kotlin allows omitting single parameter (the implicit it parameter). Kotlin compiler cannot distinguish no-arg Runnable with unary TransactionCallback<T>.

In order to disambiguate, a parameter or the callback interface should be explicitly stated:

val result = transactionTemplate.execute { _ ->
  ...
  1
}
// or
val result = transactionTemplate.execute(TransactionCallback {
  ...
  1
})

I'm not sure how to fix it. Maybe let it break for bigger convenience in Java?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 28, 2019
@sdeleuze sdeleuze self-assigned this Sep 28, 2019
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Sep 28, 2019
This commit renames the Runnable variant to executeWithoutResult and
uses a Consumer<TransactionStatus> parameter for better consistency
with TransactionCallbackWithoutResult.

Closes spring-projectsgh-23724
@jhoeller jhoeller added this to the 5.2 GA milestone Sep 29, 2019
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants