Skip to content

Commit d1f0720

Browse files
committed
LANG-1778 fix by reversing order
1 parent 3abb3a2 commit d1f0720

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.lang.reflect.TypeVariable;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
27+
import java.util.Collections;
2728
import java.util.Comparator;
2829
import java.util.Iterator;
2930
import java.util.LinkedHashSet;
@@ -382,7 +383,9 @@ public static Method getMatchingMethod(final Class<?> cls, final String methodNa
382383
.filter(method -> method.getName().equals(methodName))
383384
.collect(Collectors.toList());
384385

385-
getAllSuperclassesAndInterfaces(cls).stream()
386+
final List<Class<?>> allSuperclassesAndInterfaces = getAllSuperclassesAndInterfaces(cls);
387+
Collections.reverse(allSuperclassesAndInterfaces);
388+
allSuperclassesAndInterfaces.stream()
386389
.map(Class::getDeclaredMethods)
387390
.flatMap(Stream::of)
388391
.filter(method -> method.getName().equals(methodName))

src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class MethodUtilsTest extends AbstractLangTest {
6363
protected abstract static class AbstractGetMatchingMethod implements InterfaceGetMatchingMethod {
6464
public abstract void testMethod5(Exception exception);
6565
}
66+
protected abstract static class AbstractGetMatchingMethod2 implements InterfaceGetMatchingMethod {
67+
@Override
68+
public void testMethod6() {}
69+
}
6670

6771
interface ChildInterface {
6872
}
@@ -112,6 +116,8 @@ public void testMethod5(final Exception exception) {
112116
}
113117
}
114118

119+
private static final class ConcreteGetMatchingMethod2 extends AbstractGetMatchingMethod2 {}
120+
115121
public static class GrandParentObject {
116122
}
117123
public static class InheritanceBean {
@@ -670,6 +676,10 @@ void testGetMatchingMethod() throws NoSuchMethodException {
670676

671677
assertNullPointerException(
672678
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
679+
680+
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod2.class, "testMethod6");
681+
assertNotNull(testMethod6);
682+
assertEquals(AbstractGetMatchingMethod2.class, testMethod6.getDeclaringClass());
673683
}
674684

675685
@Test

0 commit comments

Comments
 (0)