From a271d5ec1546f7695c5b50b5fc6ae6234f6354ee Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 13 Sep 2023 16:49:24 +0200 Subject: [PATCH] Use nullSafeHashCode() in SynthesizedMergedAnnotationInvocationHandler In light of the refinements to ObjectUtils, this commit updates SynthesizedMergedAnnotationInvocationHandler to use ObjectUtils.nullSafeHashCode() and removes the now obsolete code in SynthesizedMergedAnnotationInvocationHandler. See gh-29051 --- ...izedMergedAnnotationInvocationHandler.java | 38 +------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java index 69847101d5..218d3953e5 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -22,7 +22,6 @@ import java.lang.reflect.Array; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.Arrays; import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentHashMap; @@ -136,44 +135,11 @@ final class SynthesizedMergedAnnotationInvocationHandler i for (int i = 0; i < this.attributes.size(); i++) { Method attribute = this.attributes.get(i); Object value = getAttributeValue(attribute); - hashCode += (127 * attribute.getName().hashCode()) ^ getValueHashCode(value); + hashCode += (127 * attribute.getName().hashCode()) ^ ObjectUtils.nullSafeHashCode(value); } return hashCode; } - private int getValueHashCode(Object value) { - // Use Arrays.hashCode(...) since Spring's ObjectUtils doesn't comply - // with the requirements specified in Annotation#hashCode(). - if (value instanceof boolean[] booleans) { - return Arrays.hashCode(booleans); - } - if (value instanceof byte[] bytes) { - return Arrays.hashCode(bytes); - } - if (value instanceof char[] chars) { - return Arrays.hashCode(chars); - } - if (value instanceof double[] doubles) { - return Arrays.hashCode(doubles); - } - if (value instanceof float[] floats) { - return Arrays.hashCode(floats); - } - if (value instanceof int[] ints) { - return Arrays.hashCode(ints); - } - if (value instanceof long[] longs) { - return Arrays.hashCode(longs); - } - if (value instanceof short[] shorts) { - return Arrays.hashCode(shorts); - } - if (value instanceof Object[] objects) { - return Arrays.hashCode(objects); - } - return value.hashCode(); - } - private String annotationToString() { String string = this.string; if (string == null) {