1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -243,7 +243,7 @@ public static ClassLoader overrideThreadContextClassLoader(@Nullable ClassLoader
243
243
* style (e.g. "java.lang.Thread.State" instead of "java.lang.Thread$State").
244
244
* @param name the name of the Class
245
245
* @param classLoader the class loader to use
246
- * (may be {@code null}, which indicates the default class loader)
246
+ * (can be {@code null}, which indicates the default class loader)
247
247
* @return a class instance for the supplied name
248
248
* @throws ClassNotFoundException if the class was not found
249
249
* @throws LinkageError if the class file could not be loaded
@@ -314,7 +314,7 @@ public static Class<?> forName(String name, @Nullable ClassLoader classLoader)
314
314
* the exceptions thrown in case of class loading failure.
315
315
* @param className the name of the Class
316
316
* @param classLoader the class loader to use
317
- * (may be {@code null}, which indicates the default class loader)
317
+ * (can be {@code null}, which indicates the default class loader)
318
318
* @return a class instance for the supplied name
319
319
* @throws IllegalArgumentException if the class name was not resolvable
320
320
* (that is, the class could not be found or the class file could not be loaded)
@@ -348,7 +348,7 @@ public static Class<?> resolveClassName(String className, @Nullable ClassLoader
348
348
* one of its dependencies is not present or cannot be loaded.
349
349
* @param className the name of the class to check
350
350
* @param classLoader the class loader to use
351
- * (may be {@code null} which indicates the default class loader)
351
+ * (can be {@code null} which indicates the default class loader)
352
352
* @return whether the specified class is present (including all of its
353
353
* superclasses and interfaces)
354
354
* @throws IllegalStateException if the corresponding class is resolvable but
@@ -375,7 +375,7 @@ public static boolean isPresent(String className, @Nullable ClassLoader classLoa
375
375
* Check whether the given class is visible in the given ClassLoader.
376
376
* @param clazz the class to check (typically an interface)
377
377
* @param classLoader the ClassLoader to check against
378
- * (may be {@code null} in which case this method will always return {@code true})
378
+ * (can be {@code null} in which case this method will always return {@code true})
379
379
*/
380
380
public static boolean isVisible (Class <?> clazz , @ Nullable ClassLoader classLoader ) {
381
381
if (classLoader == null ) {
@@ -399,7 +399,7 @@ public static boolean isVisible(Class<?> clazz, @Nullable ClassLoader classLoade
399
399
* i.e. whether it is loaded by the given ClassLoader or a parent of it.
400
400
* @param clazz the class to analyze
401
401
* @param classLoader the ClassLoader to potentially cache metadata in
402
- * (may be {@code null} which indicates the system class loader)
402
+ * (can be {@code null} which indicates the system class loader)
403
403
*/
404
404
public static boolean isCacheSafe (Class <?> clazz , @ Nullable ClassLoader classLoader ) {
405
405
Assert .notNull (clazz , "Class must not be null" );
@@ -663,7 +663,7 @@ public static String classNamesToString(Class<?>... classes) {
663
663
* in the given collection.
664
664
* <p>Basically like {@code AbstractCollection.toString()}, but stripping
665
665
* the "class "/"interface " prefix before every class name.
666
- * @param classes a Collection of Class objects (may be {@code null})
666
+ * @param classes a Collection of Class objects (can be {@code null})
667
667
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
668
668
* @see java.util.AbstractCollection#toString()
669
669
*/
@@ -718,7 +718,7 @@ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
718
718
* <p>If the class itself is an interface, it gets returned as sole interface.
719
719
* @param clazz the class to analyze for interfaces
720
720
* @param classLoader the ClassLoader that the interfaces need to be visible in
721
- * (may be {@code null} when accepting all declared interfaces)
721
+ * (can be {@code null} when accepting all declared interfaces)
722
722
* @return all interfaces that the given object implements as an array
723
723
*/
724
724
public static Class <?>[] getAllInterfacesForClass (Class <?> clazz , @ Nullable ClassLoader classLoader ) {
@@ -753,7 +753,7 @@ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
753
753
* <p>If the class itself is an interface, it gets returned as sole interface.
754
754
* @param clazz the class to analyze for interfaces
755
755
* @param classLoader the ClassLoader that the interfaces need to be visible in
756
- * (may be {@code null} when accepting all declared interfaces)
756
+ * (can be {@code null} when accepting all declared interfaces)
757
757
* @return all interfaces that the given object implements as a Set
758
758
*/
759
759
public static Set <Class <?>> getAllInterfacesForClassAsSet (Class <?> clazz , @ Nullable ClassLoader classLoader ) {
@@ -1082,7 +1082,7 @@ public static String getQualifiedMethodName(Method method) {
1082
1082
* fully qualified interface/class name + "." + method name.
1083
1083
* @param method the method
1084
1084
* @param clazz the clazz that the method is being invoked on
1085
- * (may be {@code null} to indicate the method's declaring class)
1085
+ * (can be {@code null} to indicate the method's declaring class)
1086
1086
* @return the qualified name of the method
1087
1087
* @since 4.3.4
1088
1088
*/
@@ -1163,7 +1163,7 @@ public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... p
1163
1163
* @param clazz the clazz to analyze
1164
1164
* @param methodName the name of the method
1165
1165
* @param paramTypes the parameter types of the method
1166
- * (may be {@code null} to indicate any signature)
1166
+ * (can be {@code null} to indicate any signature)
1167
1167
* @return the method (never {@code null})
1168
1168
* @throws IllegalStateException if the method has not been found
1169
1169
* @see Class#getMethod
@@ -1202,7 +1202,7 @@ else if (candidates.isEmpty()) {
1202
1202
* @param clazz the clazz to analyze
1203
1203
* @param methodName the name of the method
1204
1204
* @param paramTypes the parameter types of the method
1205
- * (may be {@code null} to indicate any signature)
1205
+ * (can be {@code null} to indicate any signature)
1206
1206
* @return the method, or {@code null} if not found
1207
1207
* @see Class#getMethod
1208
1208
*/
@@ -1291,13 +1291,14 @@ public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodN
1291
1291
* implementation will fall back to returning the originally provided method.
1292
1292
* @param method the method to be invoked, which may come from an interface
1293
1293
* @param targetClass the target class for the current invocation
1294
- * (may be {@code null} or may not even implement the method)
1294
+ * (can be {@code null} or may not even implement the method)
1295
1295
* @return the specific target method, or the original method if the
1296
1296
* {@code targetClass} does not implement it
1297
1297
* @see #getInterfaceMethodIfPossible(Method, Class)
1298
1298
*/
1299
1299
public static Method getMostSpecificMethod (Method method , @ Nullable Class <?> targetClass ) {
1300
- if (targetClass != null && targetClass != method .getDeclaringClass () && isOverridable (method , targetClass )) {
1300
+ if (targetClass != null && targetClass != method .getDeclaringClass () &&
1301
+ (isOverridable (method , targetClass ) || !method .getDeclaringClass ().isAssignableFrom (targetClass ))) {
1301
1302
try {
1302
1303
if (Modifier .isPublic (method .getModifiers ())) {
1303
1304
try {
0 commit comments