|
@@ -450,9 +450,11 @@ public final class ObjectUtils {
|
|
*/
|
|
*/
|
|
public static Map<String, Field> getClassFields(@NonNull Class<?> clazz) {
|
|
public static Map<String, Field> getClassFields(@NonNull Class<?> clazz) {
|
|
Map<String, Field> fields = ObjectUtils.ifNull(CLASS_FIELD_MAPPING.get(clazz), WeakReference::get);
|
|
Map<String, Field> fields = ObjectUtils.ifNull(CLASS_FIELD_MAPPING.get(clazz), WeakReference::get);
|
|
- return fields != null ? fields : CLASS_FIELD_MAPPING.computeIfAbsent(
|
|
|
|
- clazz, k -> new WeakReference<>(findClassFields(clazz))
|
|
|
|
- ).get();
|
|
|
|
|
|
+ if (fields == null) {
|
|
|
|
+ fields = findClassFields(clazz);
|
|
|
|
+ CLASS_FIELD_MAPPING.put(clazz, new WeakReference<>(fields));
|
|
|
|
+ }
|
|
|
|
+ return fields;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -874,9 +876,11 @@ public final class ObjectUtils {
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
private static <M, T extends Schema<M>> T getProtostuffSchema(@NonNull Class<M> clazz) {
|
|
private static <M, T extends Schema<M>> T getProtostuffSchema(@NonNull Class<M> clazz) {
|
|
T schema = (T) ObjectUtils.ifNull(PROTOSTUFF_SCHEMA_MAPPING.get(clazz), WeakReference::get);
|
|
T schema = (T) ObjectUtils.ifNull(PROTOSTUFF_SCHEMA_MAPPING.get(clazz), WeakReference::get);
|
|
- return schema != null ? schema : (T) PROTOSTUFF_SCHEMA_MAPPING.computeIfAbsent(
|
|
|
|
- clazz, k -> new WeakReference<>(RuntimeSchema.getSchema(clazz))
|
|
|
|
- ).get();
|
|
|
|
|
|
+ if (schema == null) {
|
|
|
|
+ schema = (T) RuntimeSchema.getSchema(clazz);
|
|
|
|
+ PROTOSTUFF_SCHEMA_MAPPING.put(clazz, new WeakReference<>(schema));
|
|
|
|
+ }
|
|
|
|
+ return schema;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -925,15 +929,17 @@ public final class ObjectUtils {
|
|
public static List<PropertyDescriptor> getPropertyDescriptors(@NonNull Class<?> clazz) {
|
|
public static List<PropertyDescriptor> getPropertyDescriptors(@NonNull Class<?> clazz) {
|
|
List<PropertyDescriptor> descriptors =
|
|
List<PropertyDescriptor> descriptors =
|
|
ObjectUtils.ifNull(PROPERTY_DESCRIPTOR_MAPPING.get(clazz), WeakReference::get);
|
|
ObjectUtils.ifNull(PROPERTY_DESCRIPTOR_MAPPING.get(clazz), WeakReference::get);
|
|
- return descriptors != null ? descriptors : PROPERTY_DESCRIPTOR_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
|
|
|
+ if (descriptors == null) {
|
|
BeanInfo bean;
|
|
BeanInfo bean;
|
|
try {
|
|
try {
|
|
bean = Introspector.getBeanInfo(clazz, Object.class);
|
|
bean = Introspector.getBeanInfo(clazz, Object.class);
|
|
} catch (IntrospectionException e) {
|
|
} catch (IntrospectionException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
- return new WeakReference<>(Arrays.asList(bean.getPropertyDescriptors()));
|
|
|
|
- }).get();
|
|
|
|
|
|
+ descriptors = Arrays.asList(bean.getPropertyDescriptors());
|
|
|
|
+ PROPERTY_DESCRIPTOR_MAPPING.put(clazz, new WeakReference<>(descriptors));
|
|
|
|
+ }
|
|
|
|
+ return descriptors;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -957,15 +963,17 @@ public final class ObjectUtils {
|
|
private static SerializedLambda lookupFunctionLambda(Serializable function) {
|
|
private static SerializedLambda lookupFunctionLambda(Serializable function) {
|
|
Class<?> clazz = function.getClass();
|
|
Class<?> clazz = function.getClass();
|
|
SerializedLambda lambda = ObjectUtils.ifNull(LAMBDA_FUNCTION_MAPPING.get(clazz), WeakReference::get);
|
|
SerializedLambda lambda = ObjectUtils.ifNull(LAMBDA_FUNCTION_MAPPING.get(clazz), WeakReference::get);
|
|
- return lambda != null ? lambda : LAMBDA_FUNCTION_MAPPING.computeIfAbsent(clazz, k -> {
|
|
|
|
|
|
+ if (lambda == null) {
|
|
try {
|
|
try {
|
|
- Method method = k.getDeclaredMethod("writeReplace");
|
|
|
|
|
|
+ Method method = clazz.getDeclaredMethod("writeReplace");
|
|
method.setAccessible(true);
|
|
method.setAccessible(true);
|
|
- return new WeakReference<>((SerializedLambda) method.invoke(function));
|
|
|
|
|
|
+ lambda = (SerializedLambda) method.invoke(function);
|
|
} catch (ReflectiveOperationException e) {
|
|
} catch (ReflectiveOperationException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
- }).get();
|
|
|
|
|
|
+ LAMBDA_FUNCTION_MAPPING.put(clazz, new WeakReference<>(lambda));
|
|
|
|
+ }
|
|
|
|
+ return lambda;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|