Skip to content

Annotations on overridden methods not found in type hierarchy with unresolved generics #35342

@sbrannen

Description

@sbrannen

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> {
}

Related Issues

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)in: messagingIssues in messaging modules (jms, messaging)in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions