diff --git a/src/main/java/org/apache/ibatis/reflection/Reflector.java b/src/main/java/org/apache/ibatis/reflection/Reflector.java index ee7dd1a6323..c8d75ed1112 100644 --- a/src/main/java/org/apache/ibatis/reflection/Reflector.java +++ b/src/main/java/org/apache/ibatis/reflection/Reflector.java @@ -64,8 +64,9 @@ public class Reflector { public Reflector(Class clazz) { type = clazz; addDefaultConstructor(clazz); - addGetMethods(clazz); - addSetMethods(clazz); + Method[] classMethods = getClassMethods(clazz); + addGetMethods(classMethods); + addSetMethods(classMethods); addFields(clazz); readablePropertyNames = getMethods.keySet().toArray(new String[0]); writablePropertyNames = setMethods.keySet().toArray(new String[0]); @@ -83,9 +84,8 @@ private void addDefaultConstructor(Class clazz) { .findAny().ifPresent(constructor -> this.defaultConstructor = constructor); } - private void addGetMethods(Class clazz) { + private void addGetMethods(Method[] methods) { Map> conflictingGetters = new HashMap<>(); - Method[] methods = getClassMethods(clazz); Arrays.stream(methods).filter(m -> m.getParameterTypes().length == 0 && PropertyNamer.isGetter(m.getName())) .forEach(m -> addMethodConflict(conflictingGetters, PropertyNamer.methodToProperty(m.getName()), m)); resolveGetterConflicts(conflictingGetters); @@ -134,9 +134,8 @@ private void addGetMethod(String name, Method method, boolean isAmbiguous) { getTypes.put(name, typeToClass(returnType)); } - private void addSetMethods(Class clazz) { + private void addSetMethods(Method[] methods) { Map> conflictingSetters = new HashMap<>(); - Method[] methods = getClassMethods(clazz); Arrays.stream(methods).filter(m -> m.getParameterTypes().length == 1 && PropertyNamer.isSetter(m.getName())) .forEach(m -> addMethodConflict(conflictingSetters, PropertyNamer.methodToProperty(m.getName()), m)); resolveSetterConflicts(conflictingSetters);