Skip to content

Make ResolvableType.isInstance respect AOP proxies - #37365

Closed
Asthenia0412 wants to merge 1 commit into
spring-projects:mainfrom
Asthenia0412:fix/resolvabletype-isinstance-proxy
Closed

Asthenia0412 wants to merge 1 commit into
spring-projects:mainfrom
Asthenia0412:fix/resolvabletype-isinstance-proxy

Conversation

@Asthenia0412

Copy link
Copy Markdown

Overview

Currently, ResolvableType::isInstance uses obj.getClass() directly, which does not account for AOP proxies:

  • For CGLIB proxies, the generated subclass name contains $$ and the generic type information should be resolved against the target user class rather than the proxy subclass.
  • For JDK dynamic proxies, the target class's generic type information is erased on the proxy class, so a parameterized type check (e.g. List<String>) fails even though the proxy implements the corresponding interface.

Changes

  • ResolvableType.isInstance(Object) now uses ClassUtils.getUserClass(obj) to unwrap CGLIB proxies before the assignability check.
  • For JDK dynamic proxies, where the generics are not available on the proxy class, the method falls back to a raw type check (resolve().isInstance(obj)).

This makes isInstance consistent with the rest of Spring's proxy handling (e.g. AbstractBeanFactory.isTypeMatch) and fixes the case described in the issue where a JDK proxy of a parameterized type was not detected as an instance.

Related Issue

Use ClassUtils.getUserClass() to unwrap CGLIB proxies so that the
target class's generic type information is available for assignability
checks. For JDK dynamic proxies, where the target class's generics are
erased on the proxy class, fall back to a raw type check against the
interfaces implemented by the proxy.

Closes spring-projectsgh-37049
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 1, 2026
@bclozel bclozel closed this Oct 1, 2026
@sbrannen sbrannen added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants