Skip to content

Commit a741410

Browse files
committed
TransactionTemplate catches undeclared checked exception and rethrows it as UndeclaredThrowableException (SPR-6361)
1 parent eb0b4f0 commit a741410

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionTemplate.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.transaction.support;
1818

19+
import java.lang.reflect.UndeclaredThrowableException;
20+
1921
import org.apache.commons.logging.Log;
2022
import org.apache.commons.logging.LogFactory;
2123

@@ -123,7 +125,7 @@ public <T> T execute(TransactionCallback<T> action) throws TransactionException
123125
}
124126
else {
125127
TransactionStatus status = this.transactionManager.getTransaction(this);
126-
T result = null;
128+
T result;
127129
try {
128130
result = action.doInTransaction(status);
129131
}
@@ -137,6 +139,11 @@ public <T> T execute(TransactionCallback<T> action) throws TransactionException
137139
rollbackOnException(status, err);
138140
throw err;
139141
}
142+
catch (Exception ex) {
143+
// Transactional code threw unexpected exception -> rollback
144+
rollbackOnException(status, ex);
145+
throw new UndeclaredThrowableException(ex, "TransactionCallback threw undeclared checked exception");
146+
}
140147
this.transactionManager.commit(status);
141148
return result;
142149
}

0 commit comments

Comments
 (0)