Skip to content

HandlerMethod.getBeanType() doesn't fully handle CGLIB-generated classes [SPR-9490] #14124

@spring-projects-issues

Description

@spring-projects-issues

Thomas Bruyelle opened SPR-9490 and commented

https://github.com/SpringSource/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java#L122

   /**
 * Returns the type of the handler for this handler method.
 * Note that if the bean type is a CGLIB-generated class, the original, user-defined class is returned.
 */
public Class<?> getBeanType() {
     if (bean instanceof String) {
          String beanName = (String) bean;
          return beanFactory.getType(beanName);
     }
     else {
          return ClassUtils.getUserClass(bean.getClass());
     }
}

When bean instanceof String is true, the method returns the CGLIB-generated class instead of the user-defined one.

ClassUtils.getUserClass() should also wrap the return of beanFactory.getType( beanName ).


Affects: 3.1.1, 3.2 M1

Metadata

Metadata

Assignees

Labels

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