aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthew Pitts (JIRA)" <>
Subject [jira] [Created] (ARIES-1415) Exception laundering in JpaTemplate impls
Date Tue, 22 Sep 2015 13:31:04 GMT
Matthew Pitts created ARIES-1415:

             Summary: Exception laundering in JpaTemplate impls
                 Key: ARIES-1415
             Project: Aries
          Issue Type: Improvement
          Components: JPA
    Affects Versions: jpa-2.2.0
            Reporter: Matthew Pitts

Currently XaJpaTemplate and ResourceLocalJpaTemplate wrap all caught exceptions in a  new
RuntimeException and throw that instead of the original. This can make it problematic to integrate
with code that wants to run txExpr methods and catch specific exceptions - like NoResultException
or other type of recoverable exception.

Perhaps a method (like launderTxException) could be added to their base class - AbstractJpaTemplate
- which could allow for additional exception laundering.

Specifically, I thinking of something that would actually attempt to instantiate a new instance
of the original exception type via reflection and populate it with the necessary detail message.
If it is unable to instantiate the original exception, then it can simply rethrow it as-is
or maintain the original behavior of wrapping it in a RuntimeException.

Something like this:

protected RuntimeException launderTxException(Throwable original, String message) {
        if (RuntimeException.class.isInstance(original)) {
            return wrapTxException(RuntimeException.class.cast(original), message);
        else {
            return new RuntimeException(message, original);

    protected RuntimeException wrapTxException(RuntimeException original, String message)
        if (message == null)
            return original;

        try {
            RuntimeException wrapper = original.getClass().getConstructor(new Class[]
            { String.class }).newInstance(message);
            return wrapper;
        catch (ReflectiveOperationException e) {
            return original;

Thoughts, comments, criticisms?

This message was sent by Atlassian JIRA

View raw message