From f285971cb34e1d44290ec4c089899a2ac1b6ed9d Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:01:56 +0100 Subject: [PATCH] Polishing --- .../CglibSubclassingInstantiationStrategy.java | 4 ++-- .../beans/factory/support/LookupOverride.java | 8 ++++---- .../beans/factory/support/MethodOverride.java | 7 ++++--- .../beans/factory/support/ReplaceOverride.java | 17 +++++++---------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java index b3da7fb62b..4b25ac2170 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -264,7 +264,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt /** * CGLIB MethodInterceptor to override methods, replacing them with a call - * to a generic MethodReplacer. + * to a generic {@link MethodReplacer}. */ private static class ReplaceOverrideMethodInterceptor extends CglibIdentitySupport implements MethodInterceptor { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java index f51af88735..9cbcbebe94 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ public class LookupOverride extends MethodOverride { /** - * Construct a new LookupOverride. + * Construct a new {@code LookupOverride}. * @param methodName the name of the method to override * @param beanName the name of the bean in the current {@code BeanFactory} that the * overridden method should return (may be {@code null} for type-based bean retrieval) @@ -60,7 +60,7 @@ public class LookupOverride extends MethodOverride { } /** - * Construct a new LookupOverride. + * Construct a new {@code LookupOverride}. * @param method the method declaration to override * @param beanName the name of the bean in the current {@code BeanFactory} that the * overridden method should return (may be {@code null} for type-based bean retrieval) @@ -73,7 +73,7 @@ public class LookupOverride extends MethodOverride { /** - * Return the name of the bean that should be returned by this method. + * Return the name of the bean that should be returned by this {@code LookupOverride}. */ @Nullable public String getBeanName() { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java index d250320dde..49ca03408e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; +import java.util.Objects; import org.springframework.beans.BeanMetadataElement; import org.springframework.lang.Nullable; @@ -107,13 +108,13 @@ public abstract class MethodOverride implements BeanMetadataElement { @Override public boolean equals(@Nullable Object other) { return (this == other || (other instanceof MethodOverride that && - ObjectUtils.nullSafeEquals(this.methodName, that.methodName) && + this.methodName.equals(that.methodName) && ObjectUtils.nullSafeEquals(this.source, that.source))); } @Override public int hashCode() { - return ObjectUtils.nullSafeHash(this.methodName, this.source); + return Objects.hash(this.methodName, this.source); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index 497c60b080..4fe5ad8462 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; /** * Extension of {@link MethodOverride} that represents an arbitrary @@ -97,22 +97,19 @@ public class ReplaceOverride extends MethodOverride { @Override public boolean equals(@Nullable Object other) { - return (other instanceof ReplaceOverride that && super.equals(other) && - ObjectUtils.nullSafeEquals(this.methodReplacerBeanName, that.methodReplacerBeanName) && - ObjectUtils.nullSafeEquals(this.typeIdentifiers, that.typeIdentifiers)); + return (other instanceof ReplaceOverride that && super.equals(that) && + this.methodReplacerBeanName.equals(that.methodReplacerBeanName) && + this.typeIdentifiers.equals(that.typeIdentifiers)); } @Override public int hashCode() { - int hashCode = super.hashCode(); - hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.methodReplacerBeanName); - hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.typeIdentifiers); - return hashCode; + return Objects.hash(this.methodReplacerBeanName, this.typeIdentifiers); } @Override public String toString() { - return "Replace override for method '" + getMethodName() + "'"; + return "ReplaceOverride for method '" + getMethodName() + "'"; } }