Skip to content

Commit 17bbc62

Browse files
committed
optimized converter lookup to avoid contention in JDK proxy check (SPR-9084)
1 parent c55362c commit 17bbc62

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 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.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.core.convert;
1718

1819
import java.lang.annotation.Annotation;
@@ -59,6 +60,7 @@ public class TypeDescriptor {
5960
typeDescriptorCache.put(String.class, new TypeDescriptor(String.class));
6061
}
6162

63+
6264
private final Class<?> type;
6365

6466
private final TypeDescriptor elementTypeDescriptor;
@@ -69,6 +71,7 @@ public class TypeDescriptor {
6971

7072
private final Annotation[] annotations;
7173

74+
7275
/**
7376
* Create a new type descriptor from a {@link MethodParameter}.
7477
* Use this constructor when a source or target conversion point is a constructor parameter, method parameter, or method return value.
@@ -96,6 +99,7 @@ public TypeDescriptor(Property property) {
9699
this(new BeanPropertyDescriptor(property));
97100
}
98101

102+
99103
/**
100104
* Create a new type descriptor from the given type.
101105
* Use this to instruct the conversion system to convert an object to a specific target type, when no type location such as a method parameter or field is available to provide additional conversion context.
@@ -207,6 +211,7 @@ public static TypeDescriptor forObject(Object source) {
207211
return (source != null ? valueOf(source.getClass()) : null);
208212
}
209213

214+
210215
/**
211216
* The type of the backing class, method parameter, field, or property described by this TypeDescriptor.
212217
* Returns primitive types as-is.
@@ -477,6 +482,7 @@ private TypeDescriptor(Class<?> mapType, TypeDescriptor keyTypeDescriptor, TypeD
477482

478483
private TypeDescriptor(Class<?> type, TypeDescriptor elementTypeDescriptor, TypeDescriptor mapKeyTypeDescriptor,
479484
TypeDescriptor mapValueTypeDescriptor, Annotation[] annotations) {
485+
480486
this.type = type;
481487
this.elementTypeDescriptor = elementTypeDescriptor;
482488
this.mapKeyTypeDescriptor = mapKeyTypeDescriptor;
@@ -538,15 +544,25 @@ public boolean equals(Object obj) {
538544
return false;
539545
}
540546
TypeDescriptor other = (TypeDescriptor) obj;
541-
boolean annotatedTypeEquals = ObjectUtils.nullSafeEquals(getType(), other.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), other.getAnnotations());
542-
if (!annotatedTypeEquals) {
547+
if (!ObjectUtils.nullSafeEquals(getType(), other.getType())) {
548+
return false;
549+
}
550+
Annotation[] ann = getAnnotations();
551+
Annotation[] otherAnn = other.getAnnotations();
552+
if (ann.length != otherAnn.length) {
543553
return false;
544554
}
555+
for (int i = 0; i < ann.length; i++) {
556+
if (!ann[i].annotationType().equals(otherAnn[i].annotationType())) {
557+
return false;
558+
}
559+
}
545560
if (isCollection() || isArray()) {
546561
return ObjectUtils.nullSafeEquals(getElementTypeDescriptor(), other.getElementTypeDescriptor());
547562
}
548563
else if (isMap()) {
549-
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) && ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor());
564+
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) &&
565+
ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor());
550566
}
551567
else {
552568
return true;

0 commit comments

Comments
 (0)