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

TransactionScope throws NullPointerException when attepting to commit #1250

Closed
KalaMariaHirmo opened this issue May 27, 2021 · 2 comments
Closed

Comments

@KalaMariaHirmo
Copy link

I attempted to make every Ktor pipeline its own transaction for atomicity.
My code:

this.intercept(ApplicationCallPipeline.Monitoring) {
    val transaction = manager.newTransaction(manager.defaultIsolationLevel)
    proceed()
    transaction.commit()
    transaction.close()
}

Thanks to coroutines the transaction I wanted to commit didn't match with what TransactionManager.currentOrNull() gave and it sometimes ended up being null. Resulting in this line in Exposed throwing a NullPointerException.

I managed to solve the issue by using suspended transactions like this:

this.intercept(ApplicationCallPipeline.Monitoring) {
    newSuspendedTransaction {
        proceed()
    }
}

The problem is that Exposed still allows a NullPointerException to be thrown.

@Tapac
Copy link
Contributor

Tapac commented May 29, 2021

Is the problem in NPE or that it throws at all? I can replace it with IllegalStateException when transactionScope used outside the transaction.

@KalaMariaHirmo
Copy link
Author

The problem is in the NPE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants