thread safety for caching
This commit is contained in:
@@ -79,6 +79,8 @@ public class TypeDescriptor {
|
|||||||
|
|
||||||
private TypeDescriptor mapValueType;
|
private TypeDescriptor mapValueType;
|
||||||
|
|
||||||
|
private Annotation[] annotations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new type descriptor from a method or constructor parameter.
|
* Create a new type descriptor from a method or constructor parameter.
|
||||||
* <p>Use this constructor when a target conversion point originates from a method parameter,
|
* <p>Use this constructor when a target conversion point originates from a method parameter,
|
||||||
@@ -245,13 +247,11 @@ public class TypeDescriptor {
|
|||||||
/**
|
/**
|
||||||
* Return the element type as a type descriptor.
|
* Return the element type as a type descriptor.
|
||||||
*/
|
*/
|
||||||
public TypeDescriptor getElementTypeDescriptor() {
|
public synchronized TypeDescriptor getElementTypeDescriptor() {
|
||||||
if (elementType != null) {
|
if (elementType == null) {
|
||||||
return elementType;
|
|
||||||
} else {
|
|
||||||
elementType = forElementType(resolveElementType());
|
elementType = forElementType(resolveElementType());
|
||||||
return elementType;
|
|
||||||
}
|
}
|
||||||
|
return elementType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -289,13 +289,11 @@ public class TypeDescriptor {
|
|||||||
/**
|
/**
|
||||||
* Returns map key type as a type descriptor.
|
* Returns map key type as a type descriptor.
|
||||||
*/
|
*/
|
||||||
public TypeDescriptor getMapKeyTypeDescriptor() {
|
public synchronized TypeDescriptor getMapKeyTypeDescriptor() {
|
||||||
if (mapKeyType != null) {
|
if (mapKeyType == null) {
|
||||||
return mapKeyType;
|
mapKeyType = forElementType(resolveMapKeyType());
|
||||||
} else {
|
|
||||||
mapKeyType = isMap() ? forElementType(resolveMapKeyType()) : null;
|
|
||||||
return mapKeyType;
|
|
||||||
}
|
}
|
||||||
|
return mapKeyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -319,13 +317,11 @@ public class TypeDescriptor {
|
|||||||
/**
|
/**
|
||||||
* Returns map value type as a type descriptor.
|
* Returns map value type as a type descriptor.
|
||||||
*/
|
*/
|
||||||
public TypeDescriptor getMapValueTypeDescriptor() {
|
public synchronized TypeDescriptor getMapValueTypeDescriptor() {
|
||||||
if (mapValueType != null) {
|
if (mapValueType == null) {
|
||||||
return mapValueType;
|
mapValueType = forElementType(resolveMapValueType());
|
||||||
} else {
|
|
||||||
mapValueType = isMap() ? forElementType(resolveMapValueType()) : null;
|
|
||||||
return mapValueType;
|
|
||||||
}
|
}
|
||||||
|
return mapValueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,23 +337,11 @@ public class TypeDescriptor {
|
|||||||
/**
|
/**
|
||||||
* Obtain the annotations associated with the wrapped parameter/field, if any.
|
* Obtain the annotations associated with the wrapped parameter/field, if any.
|
||||||
*/
|
*/
|
||||||
public Annotation[] getAnnotations() {
|
public synchronized Annotation[] getAnnotations() {
|
||||||
if (this.field != null) {
|
if (this.annotations == null) {
|
||||||
// not caching
|
this.annotations = resolveAnnotations();
|
||||||
return this.field.getAnnotations();
|
|
||||||
}
|
|
||||||
else if (this.methodParameter != null) {
|
|
||||||
if (this.methodParameter.getParameterIndex() < 0) {
|
|
||||||
// not caching
|
|
||||||
return this.methodParameter.getMethodAnnotations();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return this.methodParameter.getParameterAnnotations();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return EMPTY_ANNOTATION_ARRAY;
|
|
||||||
}
|
}
|
||||||
|
return this.annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -521,7 +505,7 @@ public class TypeDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return type != null ? GenericCollectionTypeResolver.getMapKeyType((Class<? extends Map>) this.type) : null;
|
return type != null && isMap() ? GenericCollectionTypeResolver.getMapKeyType((Class<? extends Map>) this.type) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -541,7 +525,24 @@ public class TypeDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return type != null ? GenericCollectionTypeResolver.getMapValueType((Class<? extends Map>) this.type) : null;
|
return isMap() && type != null ? GenericCollectionTypeResolver.getMapValueType((Class<? extends Map>) this.type) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Annotation[] resolveAnnotations() {
|
||||||
|
if (this.field != null) {
|
||||||
|
return this.field.getAnnotations();
|
||||||
|
}
|
||||||
|
else if (this.methodParameter != null) {
|
||||||
|
if (this.methodParameter.getParameterIndex() < 0) {
|
||||||
|
return this.methodParameter.getMethodAnnotations();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.methodParameter.getParameterAnnotations();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return EMPTY_ANNOTATION_ARRAY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user