Browse Source

Optimize find[Getter|Setter]ForProperty() in ReflectivePropertyAccessor

pull/30074/head
Sam Brannen 3 years ago
parent
commit
f3cb331e4e
  1. 15
      spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java

15
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -349,9 +349,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -349,9 +349,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@Nullable
private Method findGetterForProperty(String propertyName, Class<?> clazz, Object target) {
Method method = findGetterForProperty(propertyName, clazz, target instanceof Class);
if (method == null && target instanceof Class) {
method = findGetterForProperty(propertyName, target.getClass(), false);
boolean targetIsaClass = (target instanceof Class);
Method method = findGetterForProperty(propertyName, clazz, targetIsaClass);
if (method == null && targetIsaClass) {
// Fallback for getter instance methods in java.lang.Class.
method = findGetterForProperty(propertyName, Class.class, false);
}
return method;
}
@ -359,9 +361,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -359,9 +361,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@Nullable
private Method findSetterForProperty(String propertyName, Class<?> clazz, Object target) {
Method method = findSetterForProperty(propertyName, clazz, target instanceof Class);
if (method == null && target instanceof Class) {
method = findSetterForProperty(propertyName, target.getClass(), false);
}
// In contrast to findGetterForProperty(), we do not look for setters in
// java.lang.Class as a fallback, since Class doesn't have any public setters.
return method;
}

Loading…
Cancel
Save