-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Overview
Although we have addressed similar issues in the past in #20609 and #21683, annotations on overridden methods (such as a concrete implementation of an interface method) are still not found via the MergedAnnotations
API if the type hierarchy has unresolved generics.
The reason is that an unresolved generic will be resolved as null
by ResolvableType.resolve()
which is what we currently use in AnnotationsScanner.hasSameGenericTypeParameters(...)
, and that prevents the search algorithm from considering such methods as override candidates.
Similarly, an annotation on a parameter in an overridden method is not found via AnnotatedMethod
(and subclasses such as HandlerMethod
for Web MVC, WebFlux, and Messaging) if the type hierarchy has unresolved generics.
Example
Given the following type hierarchy, the compiler does not generate a method corresponding to processOneAndTwo(Long, String)
for GenericInterfaceImpl
. Nonetheless, one would expect an invocation of processOneAndTwo(Long, String)
to be @Transactional
since it is
effectively an invocation of processOneAndTwo(Long, C)
in GenericAbstractSuperclass
, which overrides/implements processOneAndTwo(A, B)
in GenericInterface
, which is annotated with @Transactional
.
However, the MergedAnnotations
infrastructure currently does not determine that processOneAndTwo(Long, C)
is @Transactional
since it is not able to determine that processOneAndTwo(Long, C)
overrides processOneAndTwo(A, B)
because of the unresolved generic C
.
interface GenericInterface<A, B> {
@Transactional
void processOneAndTwo(A value1, B value2);
}
abstract class GenericAbstractSuperclass<C> implements GenericInterface<Long, C> {
@Override
public void processOneAndTwo(Long value1, C value2) {
}
}
static GenericInterfaceImpl extends GenericAbstractSuperclass<String> {
}