Skip to content

Commit 4300fec

Browse files
committed
Restore ability to return original method at ClassUtils level as well
Closes gh-32365
1 parent e9110c0 commit 4300fec

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ public static boolean isFinalizeMethod(@Nullable Method method) {
194194
* this method resolves bridge methods in order to retrieve attributes from
195195
* the <i>original</i> method definition.
196196
* @param method the method to be invoked, which may come from an interface
197-
* @param targetClass the target class for the current invocation.
198-
* May be {@code null} or may not even implement the method.
197+
* @param targetClass the target class for the current invocation
198+
* (can be {@code null} or may not even implement the method)
199199
* @return the specific target method, or the original method if the
200-
* {@code targetClass} doesn't implement it or is {@code null}
200+
* {@code targetClass} does not implement it
201201
* @see org.springframework.util.ClassUtils#getMostSpecificMethod
202202
* @see org.springframework.core.BridgeMethodResolver#getMostSpecificMethod
203203
*/

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public static ClassLoader overrideThreadContextClassLoader(@Nullable ClassLoader
256256
* style (e.g. "java.lang.Thread.State" instead of "java.lang.Thread$State").
257257
* @param name the name of the Class
258258
* @param classLoader the class loader to use
259-
* (may be {@code null}, which indicates the default class loader)
259+
* (can be {@code null}, which indicates the default class loader)
260260
* @return a class instance for the supplied name
261261
* @throws ClassNotFoundException if the class was not found
262262
* @throws LinkageError if the class file could not be loaded
@@ -328,7 +328,7 @@ public static Class<?> forName(String name, @Nullable ClassLoader classLoader)
328328
* the exceptions thrown in case of class loading failure.
329329
* @param className the name of the Class
330330
* @param classLoader the class loader to use
331-
* (may be {@code null}, which indicates the default class loader)
331+
* (can be {@code null}, which indicates the default class loader)
332332
* @return a class instance for the supplied name
333333
* @throws IllegalArgumentException if the class name was not resolvable
334334
* (that is, the class could not be found or the class file could not be loaded)
@@ -362,7 +362,7 @@ public static Class<?> resolveClassName(String className, @Nullable ClassLoader
362362
* one of its dependencies is not present or cannot be loaded.
363363
* @param className the name of the class to check
364364
* @param classLoader the class loader to use
365-
* (may be {@code null} which indicates the default class loader)
365+
* (can be {@code null} which indicates the default class loader)
366366
* @return whether the specified class is present (including all of its
367367
* superclasses and interfaces)
368368
* @throws IllegalStateException if the corresponding class is resolvable but
@@ -389,7 +389,7 @@ public static boolean isPresent(String className, @Nullable ClassLoader classLoa
389389
* Check whether the given class is visible in the given ClassLoader.
390390
* @param clazz the class to check (typically an interface)
391391
* @param classLoader the ClassLoader to check against
392-
* (may be {@code null} in which case this method will always return {@code true})
392+
* (can be {@code null} in which case this method will always return {@code true})
393393
*/
394394
public static boolean isVisible(Class<?> clazz, @Nullable ClassLoader classLoader) {
395395
if (classLoader == null) {
@@ -413,7 +413,7 @@ public static boolean isVisible(Class<?> clazz, @Nullable ClassLoader classLoade
413413
* i.e. whether it is loaded by the given ClassLoader or a parent of it.
414414
* @param clazz the class to analyze
415415
* @param classLoader the ClassLoader to potentially cache metadata in
416-
* (may be {@code null} which indicates the system class loader)
416+
* (can be {@code null} which indicates the system class loader)
417417
*/
418418
public static boolean isCacheSafe(Class<?> clazz, @Nullable ClassLoader classLoader) {
419419
Assert.notNull(clazz, "Class must not be null");
@@ -727,7 +727,7 @@ public static String classNamesToString(Class<?>... classes) {
727727
* in the given collection.
728728
* <p>Basically like {@code AbstractCollection.toString()}, but stripping
729729
* the "class "/"interface " prefix before every class name.
730-
* @param classes a Collection of Class objects (may be {@code null})
730+
* @param classes a Collection of Class objects (can be {@code null})
731731
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
732732
* @see java.util.AbstractCollection#toString()
733733
*/
@@ -782,7 +782,7 @@ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
782782
* <p>If the class itself is an interface, it gets returned as sole interface.
783783
* @param clazz the class to analyze for interfaces
784784
* @param classLoader the ClassLoader that the interfaces need to be visible in
785-
* (may be {@code null} when accepting all declared interfaces)
785+
* (can be {@code null} when accepting all declared interfaces)
786786
* @return all interfaces that the given object implements as an array
787787
*/
788788
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, @Nullable ClassLoader classLoader) {
@@ -817,7 +817,7 @@ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
817817
* <p>If the class itself is an interface, it gets returned as sole interface.
818818
* @param clazz the class to analyze for interfaces
819819
* @param classLoader the ClassLoader that the interfaces need to be visible in
820-
* (may be {@code null} when accepting all declared interfaces)
820+
* (can be {@code null} when accepting all declared interfaces)
821821
* @return all interfaces that the given object implements as a Set
822822
*/
823823
public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, @Nullable ClassLoader classLoader) {
@@ -1146,7 +1146,7 @@ public static String getQualifiedMethodName(Method method) {
11461146
* fully qualified interface/class name + "." + method name.
11471147
* @param method the method
11481148
* @param clazz the clazz that the method is being invoked on
1149-
* (may be {@code null} to indicate the method's declaring class)
1149+
* (can be {@code null} to indicate the method's declaring class)
11501150
* @return the qualified name of the method
11511151
* @since 4.3.4
11521152
*/
@@ -1227,7 +1227,7 @@ public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... p
12271227
* @param clazz the clazz to analyze
12281228
* @param methodName the name of the method
12291229
* @param paramTypes the parameter types of the method
1230-
* (may be {@code null} to indicate any signature)
1230+
* (can be {@code null} to indicate any signature)
12311231
* @return the method (never {@code null})
12321232
* @throws IllegalStateException if the method has not been found
12331233
* @see Class#getMethod
@@ -1266,7 +1266,7 @@ else if (candidates.isEmpty()) {
12661266
* @param clazz the clazz to analyze
12671267
* @param methodName the name of the method
12681268
* @param paramTypes the parameter types of the method
1269-
* (may be {@code null} to indicate any signature)
1269+
* (can be {@code null} to indicate any signature)
12701270
* @return the method, or {@code null} if not found
12711271
* @see Class#getMethod
12721272
*/
@@ -1355,13 +1355,14 @@ public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodN
13551355
* implementation will fall back to returning the originally provided method.
13561356
* @param method the method to be invoked, which may come from an interface
13571357
* @param targetClass the target class for the current invocation
1358-
* (may be {@code null} or may not even implement the method)
1358+
* (can be {@code null} or may not even implement the method)
13591359
* @return the specific target method, or the original method if the
13601360
* {@code targetClass} does not implement it
13611361
* @see #getInterfaceMethodIfPossible(Method, Class)
13621362
*/
13631363
public static Method getMostSpecificMethod(Method method, @Nullable Class<?> targetClass) {
1364-
if (targetClass != null && targetClass != method.getDeclaringClass() && isOverridable(method, targetClass)) {
1364+
if (targetClass != null && targetClass != method.getDeclaringClass() &&
1365+
(isOverridable(method, targetClass) || !method.getDeclaringClass().isAssignableFrom(targetClass))) {
13651366
try {
13661367
if (Modifier.isPublic(method.getModifiers())) {
13671368
try {

0 commit comments

Comments
 (0)