提交 17bbc623 编写于 作者: J Juergen Hoeller

optimized converter lookup to avoid contention in JDK proxy check (SPR-9084)

上级 c55362c3
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.core.convert; package org.springframework.core.convert;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
...@@ -59,6 +60,7 @@ public class TypeDescriptor { ...@@ -59,6 +60,7 @@ public class TypeDescriptor {
typeDescriptorCache.put(String.class, new TypeDescriptor(String.class)); typeDescriptorCache.put(String.class, new TypeDescriptor(String.class));
} }
private final Class<?> type; private final Class<?> type;
private final TypeDescriptor elementTypeDescriptor; private final TypeDescriptor elementTypeDescriptor;
...@@ -69,6 +71,7 @@ public class TypeDescriptor { ...@@ -69,6 +71,7 @@ public class TypeDescriptor {
private final Annotation[] annotations; private final Annotation[] annotations;
/** /**
* Create a new type descriptor from a {@link MethodParameter}. * Create a new type descriptor from a {@link MethodParameter}.
* Use this constructor when a source or target conversion point is a constructor parameter, method parameter, or method return value. * 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 class TypeDescriptor { ...@@ -96,6 +99,7 @@ public class TypeDescriptor {
this(new BeanPropertyDescriptor(property)); this(new BeanPropertyDescriptor(property));
} }
/** /**
* Create a new type descriptor from the given type. * Create a new type descriptor from the given type.
* 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. * 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 class TypeDescriptor { ...@@ -207,6 +211,7 @@ public class TypeDescriptor {
return (source != null ? valueOf(source.getClass()) : null); return (source != null ? valueOf(source.getClass()) : null);
} }
/** /**
* The type of the backing class, method parameter, field, or property described by this TypeDescriptor. * The type of the backing class, method parameter, field, or property described by this TypeDescriptor.
* Returns primitive types as-is. * Returns primitive types as-is.
...@@ -477,6 +482,7 @@ public class TypeDescriptor { ...@@ -477,6 +482,7 @@ public class TypeDescriptor {
private TypeDescriptor(Class<?> type, TypeDescriptor elementTypeDescriptor, TypeDescriptor mapKeyTypeDescriptor, private TypeDescriptor(Class<?> type, TypeDescriptor elementTypeDescriptor, TypeDescriptor mapKeyTypeDescriptor,
TypeDescriptor mapValueTypeDescriptor, Annotation[] annotations) { TypeDescriptor mapValueTypeDescriptor, Annotation[] annotations) {
this.type = type; this.type = type;
this.elementTypeDescriptor = elementTypeDescriptor; this.elementTypeDescriptor = elementTypeDescriptor;
this.mapKeyTypeDescriptor = mapKeyTypeDescriptor; this.mapKeyTypeDescriptor = mapKeyTypeDescriptor;
...@@ -538,15 +544,25 @@ public class TypeDescriptor { ...@@ -538,15 +544,25 @@ public class TypeDescriptor {
return false; return false;
} }
TypeDescriptor other = (TypeDescriptor) obj; TypeDescriptor other = (TypeDescriptor) obj;
boolean annotatedTypeEquals = ObjectUtils.nullSafeEquals(getType(), other.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), other.getAnnotations()); if (!ObjectUtils.nullSafeEquals(getType(), other.getType())) {
if (!annotatedTypeEquals) { return false;
}
Annotation[] ann = getAnnotations();
Annotation[] otherAnn = other.getAnnotations();
if (ann.length != otherAnn.length) {
return false; return false;
} }
for (int i = 0; i < ann.length; i++) {
if (!ann[i].annotationType().equals(otherAnn[i].annotationType())) {
return false;
}
}
if (isCollection() || isArray()) { if (isCollection() || isArray()) {
return ObjectUtils.nullSafeEquals(getElementTypeDescriptor(), other.getElementTypeDescriptor()); return ObjectUtils.nullSafeEquals(getElementTypeDescriptor(), other.getElementTypeDescriptor());
} }
else if (isMap()) { else if (isMap()) {
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) && ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor()); return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) &&
ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor());
} }
else { else {
return true; return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册