Browse Source

Avoid misleading log message for commit-triggering exception

Closes gh-25253
5.0.x
Juergen Hoeller 6 years ago
parent
commit
7a8fc0e256
  1. 20
      spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -307,11 +307,12 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
} }
else { else {
Object result;
final ThrowableHolder throwableHolder = new ThrowableHolder(); final ThrowableHolder throwableHolder = new ThrowableHolder();
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in. // It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
try { try {
Object result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr, status -> { result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr, status -> {
TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status); TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status);
try { try {
return invocation.proceedWithInvocation(); return invocation.proceedWithInvocation();
@ -336,12 +337,6 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
cleanupTransactionInfo(txInfo); cleanupTransactionInfo(txInfo);
} }
}); });
// Check result state: It might indicate a Throwable to rethrow.
if (throwableHolder.throwable != null) {
throw throwableHolder.throwable;
}
return result;
} }
catch (ThrowableHolderException ex) { catch (ThrowableHolderException ex) {
throw ex.getCause(); throw ex.getCause();
@ -359,11 +354,17 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
} }
throw ex2; throw ex2;
} }
// Check result state: It might indicate a Throwable to rethrow.
if (throwableHolder.throwable != null) {
throw throwableHolder.throwable;
}
return result;
} }
} }
/** /**
* Clear the cache. * Clear the transaction manager cache.
*/ */
protected void clearTransactionManagerCache() { protected void clearTransactionManagerCache() {
this.transactionManagerCache.clear(); this.transactionManagerCache.clear();
@ -682,6 +683,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
@FunctionalInterface @FunctionalInterface
protected interface InvocationCallback { protected interface InvocationCallback {
@Nullable
Object proceedWithInvocation() throws Throwable; Object proceedWithInvocation() throws Throwable;
} }

Loading…
Cancel
Save