@@ -525,6 +525,30 @@ public String foo() {
525525 }
526526 }
527527
528+ public static class StaticParent {
529+ public static String who () {
530+ return "parent" ;
531+ }
532+ }
533+
534+ static class StaticChild extends StaticParent {
535+ public static String who () {
536+ return "child" ;
537+ }
538+ }
539+
540+ public interface StaticLabel {
541+ static String label () {
542+ return "interface" ;
543+ }
544+ }
545+
546+ static class InstanceLabel implements StaticLabel {
547+ public String label () {
548+ return "instance" ;
549+ }
550+ }
551+
528552 private static class TestMutable implements Mutable <Object > {
529553 @ Override
530554 public Object getValue () {
@@ -640,6 +664,20 @@ void testInvokeMethodOnNonPublicClass() throws Exception {
640664 assertNull (MethodUtils .invokeMethod (new TestMutable (), "getValue" ));
641665 }
642666
667+ @ Test
668+ void testInvokeStaticMethodOnNonPublicSubclass () throws Exception {
669+ // A static method hides rather than overrides, so the subclass's own declaration is invoked.
670+ assertSame (StaticChild .class , MethodUtils .getMatchingAccessibleMethod (StaticChild .class , "who" ).getDeclaringClass ());
671+ assertEquals ("child" , MethodUtils .invokeStaticMethod (StaticChild .class , "who" ));
672+ }
673+
674+ @ Test
675+ void testInvokeMethodIgnoresStaticInterfaceMethod () throws Exception {
676+ assertSame (InstanceLabel .class , MethodUtils .getMatchingAccessibleMethod (InstanceLabel .class , "label" ).getDeclaringClass ());
677+ assertEquals ("instance" , MethodUtils .invokeMethod (new InstanceLabel (), "label" ));
678+ assertNull (MethodUtils .getAccessibleMethod (InstanceLabel .class , "label" ));
679+ }
680+
643681 @ Test
644682 void testGetAccessibleMethodInaccessible () throws Exception {
645683 assertNull (MethodUtils .getAccessibleMethod (TestBean .class .getDeclaredMethod ("privateStuff" )));
0 commit comments