You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/07/17 16:23:50 UTC

(commons-lang) branch master updated: LANG-1778 fix by reversing order (#1414)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e4558389 LANG-1778 fix by reversing order (#1414)
1e4558389 is described below

commit 1e455838963a99f7e76e334850c00293262f9573
Author: wuwu2000 <wa...@cominto.de>
AuthorDate: Thu Jul 17 18:23:44 2025 +0200

    LANG-1778 fix by reversing order (#1414)
    
    * LANG-1778 fix by reversing order
    
    * fix checkstyle
    
    * LANG-1778 assert direct implementation for regression
---
 .../apache/commons/lang3/reflect/MethodUtils.java   |  5 ++++-
 .../commons/lang3/reflect/MethodUtilsTest.java      | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index c9a18908b..aa00ac605 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -24,6 +24,7 @@
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -382,7 +383,9 @@ public static Method getMatchingMethod(final Class<?> cls, final String methodNa
                 .filter(method -> method.getName().equals(methodName))
                 .collect(Collectors.toList());
 
-        getAllSuperclassesAndInterfaces(cls).stream()
+        final List<Class<?>> allSuperclassesAndInterfaces = getAllSuperclassesAndInterfaces(cls);
+        Collections.reverse(allSuperclassesAndInterfaces);
+        allSuperclassesAndInterfaces.stream()
                 .map(Class::getDeclaredMethods)
                 .flatMap(Stream::of)
                 .filter(method -> method.getName().equals(methodName))
diff --git a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
index 8fa5a62e1..c189f4463 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
@@ -63,6 +63,10 @@ class MethodUtilsTest extends AbstractLangTest {
     protected abstract static class AbstractGetMatchingMethod implements InterfaceGetMatchingMethod {
         public abstract void testMethod5(Exception exception);
     }
+    protected abstract static class AbstractGetMatchingMethod2 implements InterfaceGetMatchingMethod {
+        @Override
+        public void testMethod6() { }
+    }
 
     interface ChildInterface {
     }
@@ -112,6 +116,12 @@ public void testMethod5(final Exception exception) {
         }
     }
 
+    private static final class ConcreteGetMatchingMethod2 extends AbstractGetMatchingMethod2 { }
+    private static final class ConcreteGetMatchingMethod22 extends AbstractGetMatchingMethod2 {
+        @Override
+        public void testMethod6() { }
+    }
+
     public static class GrandParentObject {
     }
     public static class InheritanceBean {
@@ -670,6 +680,17 @@ void testGetMatchingMethod() throws NoSuchMethodException {
 
         assertNullPointerException(
                 () -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
+
+        {
+            final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod2.class, "testMethod6");
+            assertNotNull(testMethod6);
+            assertEquals(AbstractGetMatchingMethod2.class, testMethod6.getDeclaringClass());
+        }
+        {
+            final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod22.class, "testMethod6");
+            assertNotNull(testMethod6);
+            assertEquals(ConcreteGetMatchingMethod22.class, testMethod6.getDeclaringClass());
+        }
     }
 
     @Test