Skip to content

Commit

Permalink
Defend against lambda transaction customizers
Browse files Browse the repository at this point in the history
Update `TransactionManagerCustomizers` to deal directly with
`ClassCastExceptions` assuming that they are because a customizer is
implemented using a lambda.

See spring-projectsgh-7561
  • Loading branch information
philwebb committed Dec 30, 2016
1 parent 4b853c2 commit 3c93034
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
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;

Expand All @@ -31,6 +34,9 @@
*/
public class TransactionManagerCustomizers {

private static final Log logger = LogFactory
.getLog(TransactionManagerCustomizers.class);

private final List<PlatformTransactionManagerCustomizer<?>> customizers;

public TransactionManagerCustomizers(
Expand All @@ -56,7 +62,17 @@ public void customize(PlatformTransactionManager transactionManager) {
@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);
}
}
}

}

0 comments on commit 3c93034

Please sign in to comment.