From 3c930347c585b9e9a1ee665f5e71383b4f2e9f00 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 29 Dec 2016 16:37:13 -0800 Subject: [PATCH] Defend against lambda transaction customizers Update `TransactionManagerCustomizers` to deal directly with `ClassCastExceptions` assuming that they are because a customizer is implemented using a lambda. See gh-7561 --- .../TransactionManagerCustomizers.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionManagerCustomizers.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionManagerCustomizers.java index e44502775a..8a79946283 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionManagerCustomizers.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionManagerCustomizers.java @@ -20,6 +20,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.core.ResolvableType; import org.springframework.transaction.PlatformTransactionManager; @@ -31,6 +34,9 @@ import org.springframework.transaction.PlatformTransactionManager; */ public class TransactionManagerCustomizers { + private static final Log logger = LogFactory + .getLog(TransactionManagerCustomizers.class); + private final List> customizers; public TransactionManagerCustomizers( @@ -56,7 +62,17 @@ public class TransactionManagerCustomizers { @SuppressWarnings({ "unchecked", "rawtypes" }) private void customize(PlatformTransactionManager transactionManager, PlatformTransactionManagerCustomizer customizer) { - customizer.customize(transactionManager); + try { + customizer.customize(transactionManager); + } + catch (ClassCastException ex) { + // Possibly a lambda-defined listener which we could not resolve the generic + // event type for + if (logger.isDebugEnabled()) { + logger.debug("Non-matching transaction manager type for customizer: " + + customizer, ex); + } + } } }