Introduce ObjectUtils#nullSafeHash(Object... element)
This commit deprecates the various nullSafeHashCode methods taking array types as they are superseded by Arrays.hashCode now. This means that the now only remaining nullSafeHashCode method does not trigger a warning only if the target type is not an array. At the same time, there are multiple use of this method on several elements, handling the accumulation of hash codes. For that reason, this commit also introduces a nullSafeHash that takes an array of elements. The only difference between Objects.hash is that this method handles arrays. The codebase has been reviewed to use any of those two methods when it is possible. Closes gh-29051
This commit is contained in:
@@ -525,11 +525,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = ObjectUtils.nullSafeHashCode(getExpression());
|
||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutDeclarationScope);
|
||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterNames);
|
||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterTypes);
|
||||
return hashCode;
|
||||
return ObjectUtils.nullSafeHash(getExpression(), this.pointcutDeclarationScope,
|
||||
this.pointcutParameterNames, this.pointcutParameterTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.aspectj.weaver.tools.PointcutParser;
|
||||
import org.aspectj.weaver.tools.TypePatternMatcher;
|
||||
|
||||
@@ -124,7 +126,7 @@ public class TypePatternClassFilter implements ClassFilter {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectUtils.nullSafeHashCode(this.typePattern);
|
||||
return Objects.hashCode(this.typePattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class ClassFilters {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectUtils.nullSafeHashCode(this.filters);
|
||||
return Arrays.hashCode(this.filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,7 +170,7 @@ public abstract class ClassFilters {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectUtils.nullSafeHashCode(this.filters);
|
||||
return Arrays.hashCode(this.filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.aop.target;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -190,7 +191,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode() * 13 + ObjectUtils.nullSafeHashCode(this.targetBeanName);
|
||||
return Objects.hash(getClass(), this.targetBeanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.aop.target;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -140,7 +141,7 @@ public final class EmptyTargetSource implements TargetSource, Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return EmptyTargetSource.class.hashCode() * 13 + ObjectUtils.nullSafeHashCode(this.targetClass);
|
||||
return Objects.hash(getClass(), this.targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user