Skip to content

Commit 1e45583

Browse files
authored
LANG-1778 fix by reversing order (#1414)
* LANG-1778 fix by reversing order * fix checkstyle * LANG-1778 assert direct implementation for regression
1 parent 3abb3a2 commit 1e45583

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-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: 21 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,12 @@ public void testMethod5(final Exception exception) {
112116
}
113117
}
114118

119+
private static final class ConcreteGetMatchingMethod2 extends AbstractGetMatchingMethod2 { }
120+
private static final class ConcreteGetMatchingMethod22 extends AbstractGetMatchingMethod2 {
121+
@Override
122+
public void testMethod6() { }
123+
}
124+
115125
public static class GrandParentObject {
116126
}
117127
public static class InheritanceBean {
@@ -670,6 +680,17 @@ void testGetMatchingMethod() throws NoSuchMethodException {
670680

671681
assertNullPointerException(
672682
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
683+
684+
{
685+
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod2.class, "testMethod6");
686+
assertNotNull(testMethod6);
687+
assertEquals(AbstractGetMatchingMethod2.class, testMethod6.getDeclaringClass());
688+
}
689+
{
690+
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod22.class, "testMethod6");
691+
assertNotNull(testMethod6);
692+
assertEquals(ConcreteGetMatchingMethod22.class, testMethod6.getDeclaringClass());
693+
}
673694
}
674695

675696
@Test

0 commit comments

Comments
 (0)