Skip to content

ReflectionUtils.USER_DECLARED_METHODS does not filter methods declared in java.lang.Object #27970

@kse-music

Description

@kse-music

When I saw the AOP source code, I found that the getAdvisorMethods method in ReflectiveAspectJAdvisorFactory introspects the methods of Object, and I am confused about this.

The sample as follow,

@Aspect @EnableAspectJAutoProxy @Slf4j public class AopConfig { @Around("execution(* cn.hiboot.framework.research.spring.research.SimpleStart.*(..))") public Object around(ProceedingJoinPoint p) throws Throwable { log.info("proceed before"); Object obj = p.proceed(); log.info("proceed after); return obj; } }
@Slf4j @Import(AopConfig.class) public class SimpleStart { public SimpleStart() { log.info("execute constructor"); } public String test(){ return "test method return value"; } }
 @Test public void research(){ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SimpleStart.class); SimpleStart bean = context.getBean(SimpleStart.class); bean.test(); }

When a superclass is Object, it continues recursively, because in ReflectiveAspectJAdvisorFactory.adviceMethodFilter the mf = ReflectionUtils.USER_DECLARED_METHODS.and(method -> (AnnotationUtils.getAnnotation(method, Pointcut.class) == null)).

The source code position:

https://github.com/spring-projects/spring-framework/blob/main/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java#L369

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions