jakartaee / transactions

Welcome to the Jakarta EE Transactions API Project (formerly JTA)
https://jakartaee.github.io/transactions/
Other
28 stars 29 forks source link

CDI interceptors should marked the transaction for rollback for unchecked exceptions not only for RuntimeExceptions #191

Open ochaloup opened 3 years ago

ochaloup commented 3 years ago

The JTA specification it's not clear about behaviour of CDI interceptor in case of unchecked exceptions. That part of the spec talks explicitly about RuntimeException to cause the transaction to be marked for rollback. But the spec should use term unchecked exception instead.

The spec says now

By default checked exceptions do not result in the transactional interceptor marking the transaction for rollback and instances of RuntimeException and its subclasses do.

The part about Synchronization is correct as it says

An unchecked exception thrown by a registered Synchronization object causes the transaction to be aborted.

The text about CDI interceptor should be aligned to use term unchecked exception instead of RuntimeException.

A note from the Java Language Specification, version 11, chapter 11.1.1:

The unchecked exception classes are the run-time exception classes and the error classes.

The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.