Skip to content

Commit 2861e57

Browse files
committed
Catch and log LinkageError in getTypeForFactoryMethod
Closes gh-33075
1 parent ee7a1e8 commit 2861e57

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,20 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
813813

814814
// Common return type found: all factory methods return same type. For a non-parameterized
815815
// unique candidate, cache the full type declaration context of the target factory method.
816-
cachedReturnType = (uniqueCandidate != null ?
817-
ResolvableType.forMethodReturnType(uniqueCandidate) : ResolvableType.forClass(commonType));
818-
mbd.factoryMethodReturnType = cachedReturnType;
819-
return cachedReturnType.resolve();
816+
try {
817+
cachedReturnType = (uniqueCandidate != null ?
818+
ResolvableType.forMethodReturnType(uniqueCandidate) : ResolvableType.forClass(commonType));
819+
mbd.factoryMethodReturnType = cachedReturnType;
820+
return cachedReturnType.resolve();
821+
}
822+
catch (LinkageError err) {
823+
// E.g. a NoClassDefFoundError for a generic method return type
824+
if (logger.isDebugEnabled()) {
825+
logger.debug("Failed to resolve type for factory method of bean '" + beanName + "': " +
826+
(uniqueCandidate != null ? uniqueCandidate : commonType), err);
827+
}
828+
return null;
829+
}
820830
}
821831

822832
/**

0 commit comments

Comments
 (0)