Avoid bridge resolution for method from unrelated class hierarchy
Closes gh-32087
This commit is contained in:
@@ -86,6 +86,10 @@ public final class BridgeMethodResolver {
|
||||
* @see org.springframework.util.ClassUtils#getMostSpecificMethod
|
||||
*/
|
||||
public static Method getMostSpecificMethod(Method bridgeMethod, @Nullable Class<?> targetClass) {
|
||||
if (targetClass != null && !bridgeMethod.getDeclaringClass().isAssignableFrom(targetClass)) {
|
||||
return bridgeMethod;
|
||||
}
|
||||
|
||||
Method specificMethod = ClassUtils.getMostSpecificMethod(bridgeMethod, targetClass);
|
||||
return resolveBridgeMethod(specificMethod,
|
||||
(targetClass != null ? targetClass : specificMethod.getDeclaringClass()));
|
||||
|
||||
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Yanming Zhou
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
class BridgeMethodResolverTests {
|
||||
@@ -97,6 +98,13 @@ class BridgeMethodResolverTests {
|
||||
assertThat(bridgedMethod.getParameterTypes()[0]).isEqualTo(Date.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findBridgedMethodFromOriginalMethodNotInHierarchy() throws Exception {
|
||||
Method originalMethod = Adder.class.getMethod("add", Object.class);
|
||||
Method mostSpecificMethod = BridgeMethodResolver.getMostSpecificMethod(originalMethod, FakeAdder.class);
|
||||
assertThat(mostSpecificMethod).isSameAs(originalMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isBridgeMethodFor() throws Exception {
|
||||
Method bridged = MyBar.class.getDeclaredMethod("someMethod", String.class, Object.class);
|
||||
@@ -406,6 +414,13 @@ class BridgeMethodResolverTests {
|
||||
}
|
||||
|
||||
|
||||
public static class FakeAdder {
|
||||
|
||||
public void add(Date date) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Enclosing<T> {
|
||||
|
||||
public class Enclosed<S> {
|
||||
|
||||
Reference in New Issue
Block a user