Skip to content

Overridden interface default methods are not considered overridden #978

Closed
@sbrannen

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

Deliverables

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions