From 2861e570fdc70af032dffd4dccb17625c13adb87 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 20 Jun 2024 13:47:43 +0200 Subject: [PATCH] Catch and log LinkageError in getTypeForFactoryMethod Closes gh-33075 --- .../AbstractAutowireCapableBeanFactory.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index bd7e961326c..04bc1ede340 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -813,10 +813,20 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac // Common return type found: all factory methods return same type. For a non-parameterized // unique candidate, cache the full type declaration context of the target factory method. - cachedReturnType = (uniqueCandidate != null ? - ResolvableType.forMethodReturnType(uniqueCandidate) : ResolvableType.forClass(commonType)); - mbd.factoryMethodReturnType = cachedReturnType; - return cachedReturnType.resolve(); + try { + cachedReturnType = (uniqueCandidate != null ? + ResolvableType.forMethodReturnType(uniqueCandidate) : ResolvableType.forClass(commonType)); + mbd.factoryMethodReturnType = cachedReturnType; + return cachedReturnType.resolve(); + } + catch (LinkageError err) { + // E.g. a NoClassDefFoundError for a generic method return type + if (logger.isDebugEnabled()) { + logger.debug("Failed to resolve type for factory method of bean '" + beanName + "': " + + (uniqueCandidate != null ? uniqueCandidate : commonType), err); + } + return null; + } } /**