Skip to content

Commit a2d495d

Browse files
committed
Merge branch '6.2.x'
# Conflicts: # framework-platform/framework-platform.gradle # spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
2 parents 9406e7e + 1051592 commit a2d495d

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

framework-platform/framework-platform.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ dependencies {
127127
api("org.hibernate.orm:hibernate-core:7.0.3.Final")
128128
api("org.hibernate.validator:hibernate-validator:9.0.1.Final")
129129
api("org.hsqldb:hsqldb:2.7.4")
130-
api("org.htmlunit:htmlunit:4.10.0")
130+
api("org.htmlunit:htmlunit:4.13.0")
131131
api("org.javamoney:moneta:1.4.4")
132132
api("org.jboss.logging:jboss-logging:3.6.1.Final")
133133
api("org.jruby:jruby:9.4.12.0")
@@ -138,8 +138,8 @@ dependencies {
138138
api("org.python:jython-standalone:2.7.4")
139139
api("org.quartz-scheduler:quartz:2.3.2")
140140
api("org.reactivestreams:reactive-streams:1.0.4")
141-
api("org.seleniumhq.selenium:htmlunit3-driver:4.29.0")
142-
api("org.seleniumhq.selenium:selenium-java:4.29.0")
141+
api("org.seleniumhq.selenium:htmlunit3-driver:4.33.0")
142+
api("org.seleniumhq.selenium:selenium-java:4.33.0")
143143
api("org.skyscreamer:jsonassert:2.0-rc1")
144144
api("org.testng:testng:7.11.0")
145145
api("org.webjars:underscorejs:1.8.3")

spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,28 +617,35 @@ else if (this.joinPointStaticPartArgumentIndex != -1) {
617617
* @return the invocation result
618618
* @throws Throwable in case of invocation failure
619619
*/
620-
protected Object invokeAdviceMethod(
621-
@Nullable JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex)
622-
throws Throwable {
620+
protected @Nullable Object invokeAdviceMethod(@Nullable JoinPointMatch jpMatch,
621+
@Nullable Object returnValue, @Nullable Throwable ex) throws Throwable {
623622

624623
return invokeAdviceMethodWithGivenArgs(argBinding(getJoinPoint(), jpMatch, returnValue, ex));
625624
}
626625

627626
// As above, but in this case we are given the join point.
628-
protected Object invokeAdviceMethod(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
627+
protected @Nullable Object invokeAdviceMethod(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
629628
@Nullable Object returnValue, @Nullable Throwable t) throws Throwable {
630629

631630
return invokeAdviceMethodWithGivenArgs(argBinding(jp, jpMatch, returnValue, t));
632631
}
633632

634-
protected Object invokeAdviceMethodWithGivenArgs(@Nullable Object[] args) throws Throwable {
633+
protected @Nullable Object invokeAdviceMethodWithGivenArgs(@Nullable Object[] args) throws Throwable {
635634
@Nullable Object[] actualArgs = args;
636635
if (this.aspectJAdviceMethod.getParameterCount() == 0) {
637636
actualArgs = null;
638637
}
638+
Object aspectInstance = this.aspectInstanceFactory.getAspectInstance();
639+
if (aspectInstance.equals(null)) {
640+
// Possibly a NullBean -> simply proceed if necessary.
641+
if (getJoinPoint() instanceof ProceedingJoinPoint pjp) {
642+
return pjp.proceed();
643+
}
644+
return null;
645+
}
639646
try {
640647
ReflectionUtils.makeAccessible(this.aspectJAdviceMethod);
641-
return this.aspectJAdviceMethod.invoke(this.aspectInstanceFactory.getAspectInstance(), actualArgs);
648+
return this.aspectJAdviceMethod.invoke(aspectInstance, actualArgs);
642649
}
643650
catch (IllegalArgumentException ex) {
644651
throw new AopInvocationException("Mismatch on arguments to advice method [" +

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jspecify.annotations.Nullable;
2222

2323
import org.springframework.beans.factory.BeanFactory;
24+
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
2425
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2526
import org.springframework.core.Ordered;
2627
import org.springframework.core.annotation.OrderUtils;
@@ -129,7 +130,12 @@ public int getOrder() {
129130
Class<?> type = this.beanFactory.getType(this.name);
130131
if (type != null) {
131132
if (Ordered.class.isAssignableFrom(type) && this.beanFactory.isSingleton(this.name)) {
132-
return ((Ordered) this.beanFactory.getBean(this.name)).getOrder();
133+
try {
134+
return this.beanFactory.getBean(this.name, Ordered.class).getOrder();
135+
}
136+
catch (BeanNotOfRequiredTypeException ex) {
137+
// Not actually implementing Ordered -> possibly a NullBean.
138+
}
133139
}
134140
return OrderUtils.getOrder(type, Ordered.LOWEST_PRECEDENCE);
135141
}

spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ void lambdaIsAlwaysProxiedWithJdkProxyWithIntroductions(Class<?> configClass) {
364364
}
365365
}
366366

367+
@Test
368+
void nullAdviceIsSkipped() {
369+
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ProxyWithNullAdviceConfig.class)) {
370+
@SuppressWarnings("unchecked")
371+
Supplier<String> supplier = context.getBean(Supplier.class);
372+
assertThat(AopUtils.isAopProxy(supplier)).as("AOP proxy").isTrue();
373+
assertThat(supplier.get()).isEqualTo("lambda");
374+
}
375+
}
376+
367377
private ClassPathXmlApplicationContext newContext(String fileSuffix) {
368378
return new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-" + fileSuffix, getClass());
369379
}
@@ -627,6 +637,16 @@ class ProxyTargetClassFalseConfig extends AbstractProxyTargetClassConfig {
627637
class ProxyTargetClassTrueConfig extends AbstractProxyTargetClassConfig {
628638
}
629639

640+
@Configuration(proxyBeanMethods = false)
641+
@EnableAspectJAutoProxy(proxyTargetClass = true)
642+
class ProxyWithNullAdviceConfig extends AbstractProxyTargetClassConfig {
643+
644+
@Override
645+
SupplierAdvice supplierAdvice() {
646+
return null;
647+
}
648+
}
649+
630650
@Configuration
631651
@EnableAspectJAutoProxy(proxyTargetClass = true)
632652
class PerTargetProxyTargetClassTrueConfig {

0 commit comments

Comments
 (0)