Overridden interface default methods are not considered overridden #978
Description
Overview
This is a follow-up to #976.
Whether or not the bug described in this issue existed at a previous point in time is currently unknown (simply because it has not been researched).
In any case, we now have a situation where an overridden interface default method is not considered to be overridden by the findMethods()
search algorithm in ReflectionUtils
.
Consequently, if we execute all tests in the following GenericTestCaseWithOverriddenDefaultMethod
JUnit Jupiter based test class, we see that 3 tests are executed instead of 2. Specifically, we expect that only test(Long)
and test(Double)
will be executed; however, test(Number)
is additionally discovered resulting in test(Long)
being executed twice.
@ExtendWith({ LongParameterResolver.class, DoubleParameterResolver.class })
interface GenericTestInterface<N extends Number> {
@Test
default void test(N number) {
}
}
class GenericTestCaseWithOverriddenDefaultMethod implements GenericTestInterface<Long> {
@Test
@Override
public void test(Long number) {
}
@Test
void test(Double number) {
}
}
Analysis
The recent series of Whac-A-Mole bug fixes in this area leads to me believe that the only real solution to this set of problems is one that takes into account the actual generic and parameterized type information instead of relying on a best-guess approach involving method sub-signatures and blind checks for the presence of generics.
Depending on how we take into account the actual generic and parameterized type information, we might potentially wish to reverse a subset of changes in fae5b6a that explicitly treat default methods as locally declared methods (while leaving the other changes in that commit in tact).
Further Considerations
This issue currently only focuses on overridden interface default methods; however, it may well be the case that our findMethods()
search algorithm contains other bugs related to generics.
Related Issues
- Support bridged methods in ReflectionUtils.findAllMethodsInHierarchy() #333
- ReflectionUtils considers locally overloaded default methods as overridden #976
Deliverables
- Ensure that overridden interface default methods are not returned in the results of
ReflectionUtils.findMethods()
. - Investigate possible additional bugs hinted at in Further Considerations.
- to be addressed in Introduce additional tests for support of generics #981
Activity