Skip to content

Commit a271d5e

Browse files
committed
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
1 parent af13967 commit a271d5e

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
2222
import java.lang.reflect.InvocationHandler;
2323
import java.lang.reflect.Method;
2424
import java.lang.reflect.Proxy;
25-
import java.util.Arrays;
2625
import java.util.Map;
2726
import java.util.NoSuchElementException;
2827
import java.util.concurrent.ConcurrentHashMap;
@@ -136,44 +135,11 @@ private Integer computeHashCode() {
136135
for (int i = 0; i < this.attributes.size(); i++) {
137136
Method attribute = this.attributes.get(i);
138137
Object value = getAttributeValue(attribute);
139-
hashCode += (127 * attribute.getName().hashCode()) ^ getValueHashCode(value);
138+
hashCode += (127 * attribute.getName().hashCode()) ^ ObjectUtils.nullSafeHashCode(value);
140139
}
141140
return hashCode;
142141
}
143142

144-
private int getValueHashCode(Object value) {
145-
// Use Arrays.hashCode(...) since Spring's ObjectUtils doesn't comply
146-
// with the requirements specified in Annotation#hashCode().
147-
if (value instanceof boolean[] booleans) {
148-
return Arrays.hashCode(booleans);
149-
}
150-
if (value instanceof byte[] bytes) {
151-
return Arrays.hashCode(bytes);
152-
}
153-
if (value instanceof char[] chars) {
154-
return Arrays.hashCode(chars);
155-
}
156-
if (value instanceof double[] doubles) {
157-
return Arrays.hashCode(doubles);
158-
}
159-
if (value instanceof float[] floats) {
160-
return Arrays.hashCode(floats);
161-
}
162-
if (value instanceof int[] ints) {
163-
return Arrays.hashCode(ints);
164-
}
165-
if (value instanceof long[] longs) {
166-
return Arrays.hashCode(longs);
167-
}
168-
if (value instanceof short[] shorts) {
169-
return Arrays.hashCode(shorts);
170-
}
171-
if (value instanceof Object[] objects) {
172-
return Arrays.hashCode(objects);
173-
}
174-
return value.hashCode();
175-
}
176-
177143
private String annotationToString() {
178144
String string = this.string;
179145
if (string == null) {

0 commit comments

Comments
 (0)