Select method with resolved return type match (among multiple candidates)

Removes unnecessary array type check for parameters of candidate methods.

Closes gh-35936
This commit is contained in:
Juergen Hoeller
2025-12-01 23:25:59 +01:00
parent 68231aa08c
commit 92e9543ad4
2 changed files with 75 additions and 26 deletions
@@ -44,17 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("rawtypes")
class BridgeMethodResolverTests {
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<SettingsDaoImpl> targetType) {
Method[] methods = targetType.getMethods();
for (Method m : methods) {
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) {
return m;
}
}
return null;
}
@Test
void findBridgedMethod() throws Exception {
Method unbridged = MyFoo.class.getDeclaredMethod("someMethod", String.class, Object.class);
@@ -106,6 +95,24 @@ class BridgeMethodResolverTests {
assertThat(mostSpecificMethod).isSameAs(originalMethod);
}
@Test
void findBridgedMethodWithDefaultMethodInInterfaceHierarchy() throws Exception {
Method getValueDefault = DefaultMethods.class.getMethod("getValue");
Method getValuesDefault = DefaultMethods.class.getMethod("getValues");
Method getValueArgDefault = DefaultMethods.class.getMethod("getValue", Integer.class);
Method getValuesArgDefault = DefaultMethods.class.getMethod("getValues", Integer[].class);
for (Method method : ConcreteMethods.class.getMethods()) {
if (method.getName().equals("getValue")) {
assertThat(BridgeMethodResolver.findBridgedMethod(method)).isEqualTo(
method.getParameterCount() > 0 ? getValueArgDefault : getValueDefault);
}
else if (method.getName().equals("getValues")) {
assertThat(BridgeMethodResolver.findBridgedMethod(method)).isEqualTo(
method.getParameterCount() > 0 ? getValuesArgDefault : getValuesDefault);
}
}
}
@Test
void findBridgedMethodInHierarchyWithBoundedGenerics() throws Exception {
Method originalMethod = Bar.class.getDeclaredMethod("someMethod", Object.class, Object.class);
@@ -161,6 +168,16 @@ class BridgeMethodResolverTests {
assertThat(BridgeMethodResolver.findBridgedMethod(loadWithSettingsReturn)).isEqualTo(method);
}
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<?> targetType) {
Method[] methods = targetType.getMethods();
for (Method m : methods) {
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) {
return m;
}
}
return null;
}
@Test
void findBridgedMethodFromParent() throws Exception {
Method loadFromParentBridge = SettingsDaoImpl.class.getMethod("loadFromParent");
@@ -451,6 +468,44 @@ class BridgeMethodResolverTests {
}
interface InterfaceMethods<T> {
T getValue();
T[] getValues();
T getValue(T arg);
T[] getValues(T[] args);
}
interface DefaultMethods extends InterfaceMethods<Integer> {
default Integer getValue() {
return 0;
}
default Integer[] getValues() {
return new Integer[0];
}
@Override
default Integer getValue(Integer arg) {
return 0;
}
@Override
default Integer[] getValues(Integer[] args) {
return new Integer[0];
}
}
static class ConcreteMethods implements DefaultMethods {
}
public static class Enclosing<T> {
public class Enclosed<S> {