Skip to content

Commit a08bf8c

Browse files
committed
Avoid misleading log message for commit-triggering exception
Closes gh-25253
1 parent d51abe4 commit a08bf8c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -192,7 +192,7 @@ protected TransactionAspectSupport() {
192192

193193
/**
194194
* Specify the name of the default transaction manager bean.
195-
* This can either point to a traditional {@link PlatformTransactionManager} or a
195+
* <p>This can either point to a traditional {@link PlatformTransactionManager} or a
196196
* {@link ReactiveTransactionManager} for reactive transaction management.
197197
*/
198198
public void setTransactionManagerBeanName(@Nullable String transactionManagerBeanName) {
@@ -209,7 +209,7 @@ protected final String getTransactionManagerBeanName() {
209209

210210
/**
211211
* Specify the <em>default</em> transaction manager to use to drive transactions.
212-
* This can either be a traditional {@link PlatformTransactionManager} or a
212+
* <p>This can either be a traditional {@link PlatformTransactionManager} or a
213213
* {@link ReactiveTransactionManager} for reactive transaction management.
214214
* <p>The default transaction manager will be used if a <em>qualifier</em>
215215
* has not been declared for a given transaction or if an explicit name for the
@@ -222,7 +222,7 @@ public void setTransactionManager(@Nullable TransactionManager transactionManage
222222

223223
/**
224224
* Return the default transaction manager, or {@code null} if unknown.
225-
* This can either be a traditional {@link PlatformTransactionManager} or a
225+
* <p>This can either be a traditional {@link PlatformTransactionManager} or a
226226
* {@link ReactiveTransactionManager} for reactive transaction management.
227227
*/
228228
@Nullable
@@ -375,7 +375,7 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
375375
cleanupTransactionInfo(txInfo);
376376
}
377377

378-
if (vavrPresent && VavrDelegate.isVavrTry(retVal)) {
378+
if (retVal != null && vavrPresent && VavrDelegate.isVavrTry(retVal)) {
379379
// Set rollback-only in case of Vavr failure matching our rollback rules...
380380
TransactionStatus status = txInfo.getTransactionStatus();
381381
if (status != null && txAttr != null) {
@@ -388,15 +388,16 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
388388
}
389389

390390
else {
391+
Object result;
391392
final ThrowableHolder throwableHolder = new ThrowableHolder();
392393

393394
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
394395
try {
395-
Object result = ((CallbackPreferringPlatformTransactionManager) ptm).execute(txAttr, status -> {
396+
result = ((CallbackPreferringPlatformTransactionManager) ptm).execute(txAttr, status -> {
396397
TransactionInfo txInfo = prepareTransactionInfo(ptm, txAttr, joinpointIdentification, status);
397398
try {
398399
Object retVal = invocation.proceedWithInvocation();
399-
if (vavrPresent && VavrDelegate.isVavrTry(retVal)) {
400+
if (retVal != null && vavrPresent && VavrDelegate.isVavrTry(retVal)) {
400401
// Set rollback-only in case of Vavr failure matching our rollback rules...
401402
retVal = VavrDelegate.evaluateTryFailure(retVal, txAttr, status);
402403
}
@@ -422,12 +423,6 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
422423
cleanupTransactionInfo(txInfo);
423424
}
424425
});
425-
426-
// Check result state: It might indicate a Throwable to rethrow.
427-
if (throwableHolder.throwable != null) {
428-
throw throwableHolder.throwable;
429-
}
430-
return result;
431426
}
432427
catch (ThrowableHolderException ex) {
433428
throw ex.getCause();
@@ -445,11 +440,17 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
445440
}
446441
throw ex2;
447442
}
443+
444+
// Check result state: It might indicate a Throwable to rethrow.
445+
if (throwableHolder.throwable != null) {
446+
throw throwableHolder.throwable;
447+
}
448+
return result;
448449
}
449450
}
450451

451452
/**
452-
* Clear the cache.
453+
* Clear the transaction manager cache.
453454
*/
454455
protected void clearTransactionManagerCache() {
455456
this.transactionManagerCache.clear();
@@ -780,6 +781,7 @@ public String toString() {
780781
@FunctionalInterface
781782
protected interface InvocationCallback {
782783

784+
@Nullable
783785
Object proceedWithInvocation() throws Throwable;
784786
}
785787

0 commit comments

Comments
 (0)