Merge branch '5.1.x'

This commit is contained in:
Juergen Hoeller
2019-07-05 18:22:02 +02:00
11 changed files with 207 additions and 115 deletions

View File

@@ -138,6 +138,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
// The readerCache will only contain gettable properties (let's not worry about setters for now).
Property property = new Property(type, method, null);
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
method = ClassUtils.getInterfaceMethodIfPossible(method);
this.readerCache.put(cacheKey, new InvokerPair(method, typeDescriptor));
this.typeDescriptorCache.put(cacheKey, typeDescriptor);
return true;
@@ -180,6 +181,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
// The readerCache will only contain gettable properties (let's not worry about setters for now).
Property property = new Property(type, method, null);
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
method = ClassUtils.getInterfaceMethodIfPossible(method);
invoker = new InvokerPair(method, typeDescriptor);
this.lastReadInvokerPair = invoker;
this.readerCache.put(cacheKey, invoker);
@@ -239,6 +241,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
// Treat it like a property
Property property = new Property(type, null, method);
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
method = ClassUtils.getInterfaceMethodIfPossible(method);
this.writerCache.put(cacheKey, method);
this.typeDescriptorCache.put(cacheKey, typeDescriptor);
return true;
@@ -287,6 +290,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (method == null) {
method = findSetterForProperty(name, type, target);
if (method != null) {
method = ClassUtils.getInterfaceMethodIfPossible(method);
cachedMember = method;
this.writerCache.put(cacheKey, cachedMember);
}
@@ -414,13 +418,24 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
method.getParameterCount() == numberOfParams &&
(!mustBeStatic || Modifier.isStatic(method.getModifiers())) &&
(requiredReturnTypes.isEmpty() || requiredReturnTypes.contains(method.getReturnType()))) {
return ClassUtils.getInterfaceMethodIfPossible(method);
return method;
}
}
}
return null;
}
/**
* Return class methods ordered with non-bridge methods appearing higher.
*/
private Method[] getSortedMethods(Class<?> clazz) {
return this.sortedMethodsCache.computeIfAbsent(clazz, key -> {
Method[] methods = key.getMethods();
Arrays.sort(methods, (o1, o2) -> (o1.isBridge() == o2.isBridge() ? 0 : (o1.isBridge() ? 1 : -1)));
return methods;
});
}
/**
* Determine whether the given {@code Method} is a candidate for property access
* on an instance of the given target class.
@@ -434,17 +449,6 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return true;
}
/**
* Return class methods ordered with non-bridge methods appearing higher.
*/
private Method[] getSortedMethods(Class<?> clazz) {
return this.sortedMethodsCache.computeIfAbsent(clazz, key -> {
Method[] methods = key.getMethods();
Arrays.sort(methods, (o1, o2) -> (o1.isBridge() == o2.isBridge() ? 0 : (o1.isBridge() ? 1 : -1)));
return methods;
});
}
/**
* Return the method suffixes for a given property name. The default implementation
* uses JavaBean conventions with additional support for properties of the form 'xY'
@@ -536,7 +540,9 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (method == null) {
method = findGetterForProperty(name, clazz, target);
if (method != null) {
invocationTarget = new InvokerPair(method, new TypeDescriptor(new MethodParameter(method, -1)));
TypeDescriptor typeDescriptor = new TypeDescriptor(new MethodParameter(method, -1));
method = ClassUtils.getInterfaceMethodIfPossible(method);
invocationTarget = new InvokerPair(method, typeDescriptor);
ReflectionUtils.makeAccessible(method);
this.readerCache.put(cacheKey, invocationTarget);
}