Leniently tolerate null bean as aspect instance

Closes gh-35074
This commit is contained in:
Juergen Hoeller
2025-07-07 14:26:19 +02:00
parent ad00aebaa3
commit 3bd96f72a6
3 changed files with 40 additions and 7 deletions
@@ -364,6 +364,16 @@ class AspectJAutoProxyCreatorTests {
}
}
@Test
void nullAdviceIsSkipped() {
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ProxyWithNullAdviceConfig.class)) {
@SuppressWarnings("unchecked")
Supplier<String> supplier = context.getBean(Supplier.class);
assertThat(AopUtils.isAopProxy(supplier)).as("AOP proxy").isTrue();
assertThat(supplier.get()).isEqualTo("lambda");
}
}
private ClassPathXmlApplicationContext newContext(String fileSuffix) {
return new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-" + fileSuffix, getClass());
}
@@ -627,6 +637,16 @@ class ProxyTargetClassFalseConfig extends AbstractProxyTargetClassConfig {
class ProxyTargetClassTrueConfig extends AbstractProxyTargetClassConfig {
}
@Configuration(proxyBeanMethods = false)
@EnableAspectJAutoProxy(proxyTargetClass = true)
class ProxyWithNullAdviceConfig extends AbstractProxyTargetClassConfig {
@Override
SupplierAdvice supplierAdvice() {
return null;
}
}
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
class PerTargetProxyTargetClassTrueConfig {