[LANG-1694] MethodUtils.getMatchingMethod() fails with "Found multiple candidates" (#1033)
* [LANG-1694]'MethodUtils.getMatchingMethod' fails with "Found multiple candidates" when the method is abstract * [LANG-1694]MethodUtilsTest modify the modifier‘s order * [LANG-1694]MethodUtils.getMatchingMethod modify PMD check
This commit is contained in:
parent
be210cfa28
commit
d47dc7af76
|
@ -751,7 +751,8 @@ public class MethodUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Method> bestCandidates = candidates.values().iterator().next();
|
final List<Method> bestCandidates = candidates.values().iterator().next();
|
||||||
if (bestCandidates.size() == 1) {
|
if (bestCandidates.size() == 1 || !Objects.equals(bestCandidates.get(0).getDeclaringClass(),
|
||||||
|
bestCandidates.get(1).getDeclaringClass())) {
|
||||||
return bestCandidates.get(0);
|
return bestCandidates.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1053,6 +1053,9 @@ public class MethodUtilsTest extends AbstractLangTest {
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class,
|
assertThrows(IllegalStateException.class,
|
||||||
() -> MethodUtils.getMatchingMethod(GetMatchingMethodClass.class, "testMethod4", null, null));
|
() -> MethodUtils.getMatchingMethod(GetMatchingMethodClass.class, "testMethod4", null, null));
|
||||||
|
|
||||||
|
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodImpl.class, "testMethod5", RuntimeException.class),
|
||||||
|
GetMatchingMethodImpl.class.getMethod("testMethod5", Exception.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class GetMatchingMethodClass {
|
private static final class GetMatchingMethodClass {
|
||||||
|
@ -1089,4 +1092,14 @@ public class MethodUtilsTest extends AbstractLangTest {
|
||||||
public void testMethod4(final Color aColor1, final Color aColor2) {
|
public void testMethod4(final Color aColor1, final Color aColor2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract static class AbstractGetMatchingMethod {
|
||||||
|
public abstract void testMethod5(Exception exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GetMatchingMethodImpl extends AbstractGetMatchingMethod {
|
||||||
|
@Override
|
||||||
|
public void testMethod5(final Exception exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue