From 08237da4b4e7b856e02e24f289d5b28511a739d6 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 23 Sep 2023 12:40:23 +0200 Subject: [PATCH] Simplify equals() implementation in PerTargetInstantiationModelPointcut For equivalence, we only need to compare the preInstantiationPointcut fields since they include the declaredPointcut fields. In addition, we should not compare the aspectInstanceFactory fields since LazySingletonAspectInstanceFactoryDecorator does not implement equals(). See gh-31238 --- .../InstantiationModelAwarePointcutAdvisorImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java index dd97da3228..89a77213e0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java @@ -302,10 +302,12 @@ final class InstantiationModelAwarePointcutAdvisorImpl @Override public boolean equals(@Nullable Object other) { + // For equivalence, we only need to compare the preInstantiationPointcut fields since + // they include the declaredPointcut fields. In addition, we should not compare the + // aspectInstanceFactory fields since LazySingletonAspectInstanceFactoryDecorator does + // not implement equals(). return (this == other || (other instanceof PerTargetInstantiationModelPointcut that && - ObjectUtils.nullSafeEquals(this.declaredPointcut, that.declaredPointcut) && - ObjectUtils.nullSafeEquals(this.preInstantiationPointcut, that.preInstantiationPointcut) && - ObjectUtils.nullSafeEquals(this.aspectInstanceFactory, that.aspectInstanceFactory))); + ObjectUtils.nullSafeEquals(this.preInstantiationPointcut, that.preInstantiationPointcut))); } @Override