@@ -868,6 +868,49 @@ void privateSubclassOverridesMethodInPublicSuperclass() throws Exception {
868868 assertPubliclyAccessible (publiclyAccessibleMethod );
869869 }
870870
871+ @ Test // gh-35667
872+ void staticMethodInPublicClass () throws Exception {
873+ Method originalMethod = PublicSuperclass .class .getMethod ("getCacheKey" );
874+
875+ // Prerequisite: method must be public static for this use case.
876+ assertPublic (originalMethod );
877+ assertStatic (originalMethod );
878+
879+ Method publiclyAccessibleMethod = ClassUtils .getPubliclyAccessibleMethodIfPossible (originalMethod , null );
880+ assertThat (publiclyAccessibleMethod ).isSameAs (originalMethod );
881+ assertPubliclyAccessible (publiclyAccessibleMethod );
882+ }
883+
884+ @ Test // gh-35667
885+ void publicSubclassHidesStaticMethodInPublicSuperclass () throws Exception {
886+ Method originalMethod = PublicSubclass .class .getMethod ("getCacheKey" );
887+
888+ // Prerequisite: type must be public for this use case.
889+ assertPublic (originalMethod .getDeclaringClass ());
890+ // Prerequisite: method must be public static for this use case.
891+ assertPublic (originalMethod );
892+ assertStatic (originalMethod );
893+
894+ Method publiclyAccessibleMethod = ClassUtils .getPubliclyAccessibleMethodIfPossible (originalMethod , null );
895+ assertThat (publiclyAccessibleMethod ).isSameAs (originalMethod );
896+ assertPubliclyAccessible (publiclyAccessibleMethod );
897+ }
898+
899+ @ Test // gh-35667
900+ void privateSubclassHidesStaticMethodInPublicSuperclass () throws Exception {
901+ Method originalMethod = PrivateSubclass .class .getMethod ("getCacheKey" );
902+
903+ // Prerequisite: type must not be public for this use case.
904+ assertNotPublic (originalMethod .getDeclaringClass ());
905+ // Prerequisite: method must be public static for this use case.
906+ assertPublic (originalMethod );
907+ assertStatic (originalMethod );
908+
909+ Method publiclyAccessibleMethod = ClassUtils .getPubliclyAccessibleMethodIfPossible (originalMethod , null );
910+ assertThat (publiclyAccessibleMethod ).isSameAs (originalMethod );
911+ assertNotPubliclyAccessible (publiclyAccessibleMethod );
912+ }
913+
871914 }
872915
873916
@@ -914,6 +957,10 @@ private static boolean isPublic(Member member) {
914957 return Modifier .isPublic (member .getModifiers ());
915958 }
916959
960+ private static void assertStatic (Member member ) {
961+ assertThat (Modifier .isStatic (member .getModifiers ())).as ("%s must be static" , member ).isTrue ();
962+ }
963+
917964
918965 @ Target (ElementType .METHOD )
919966 @ Retention (RetentionPolicy .RUNTIME )
@@ -1048,8 +1095,27 @@ private interface PrivateInterface {
10481095 String greet (String name );
10491096 }
10501097
1098+ public static class PublicSubclass extends PublicSuperclass {
1099+
1100+ /**
1101+ * This method intentionally has the exact same signature as
1102+ * {@link PublicSuperclass#getCacheKey()}.
1103+ */
1104+ public static String getCacheKey () {
1105+ return "child" ;
1106+ }
1107+ }
1108+
10511109 private static class PrivateSubclass extends PublicSuperclass implements PublicInterface , PrivateInterface {
10521110
1111+ /**
1112+ * This method intentionally has the exact same signature as
1113+ * {@link PublicSuperclass#getCacheKey()}.
1114+ */
1115+ public static String getCacheKey () {
1116+ return "child" ;
1117+ }
1118+
10531119 @ Override
10541120 public int getNumber () {
10551121 return 2 ;
0 commit comments