If we use prototype-scoped aspect and use args
pointcut expression, it will throw warning no match for this type name: ss [Xlint:invalidAbsoluteTypeName]
,the arg havn't be binding.
Code like bellow:
@Aspect("perthis(execution(* com.tom.test.demo..*(..)))")
@Component
@Scope("prototype")
public class AspectJ {
@Before("execution(* com.tom.test.demo..*(..)) && args(ss)")
public <T extends String> void pointCut(JoinPoint joinPoint,String ss) {
System.out.println("????????????????????????");
}
}
This will throw exception
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: ss [Xlint:invalidAbsoluteTypeName]
If we use the follow code it will run well,but advise can't obtain parameter
@Aspect("perthis(execution(* com.tom.test.demo..*(..)))")
@Component
@Scope("prototype")
public class AspectJ {
@Before("execution(* com.tom.test.demo..*(..)) && args(java.lang.String)")
public <T extends String> void pointCut(JoinPoint joinPoint) {
System.out.println("????????????????????????");
}
}
Is this a bug, or is it meant to work so?
Comment From: rstoyanchev
I'm not sure if prototype scope applies to an @Aspect
and I'm not sure what it would mean. Can you clarify what your expectation with that declaration? @jhoeller is this even an expected combination?
Comment From: ZhongGuoDragon
see code class org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl
you will see if you use @Aspect(perthis())
or @Aspect((pertarget))
it will create PerTargetInstantiationModelPointcut
if (aspectInstanceFactory.getAspectMetadata().isLazilyInstantiated()) { // Static part of the pointcut is a lazy type. Pointcut preInstantiationPointcut = Pointcuts.union( aspectInstanceFactory.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut);
// Make it dynamic: must mutate from pre-instantiation to post-instantiation state. // If it's not a dynamic pointcut, it may be optimized out // by the Spring AOP infrastructure after the first evaluation. this.pointcut = new PerTargetInstantiationModelPointcut( this.declaredPointcut, preInstantiationPointcut, aspectInstanceFactory); this.lazy = true; }
it will create tow pointcut but the second pointcut without args binding, it will throw exception Caused by: java.lang.IllegalArgumentException: warning no match for this type name: ss [Xlint:invalidAbsoluteTypeName]
if you use like below:
@Aspect("perthis(execution(* com.tom.test.demo..*(..)))")
@Component
@Scope("prototype")
public class AspectJ {
@Before("execution(* com.tom.test.demo..*(..)) && args(ss)")
public <T extends String> void pointCut(JoinPoint joinPoint,String ss) {
System.out.println("????????????????????????");
}
}
Comment From: ZhongGuoDragon
I'm not sure if prototype scope applies to an
@Aspect
and I'm not sure what it would mean. Can you clarify what your expectation with that declaration? @jhoeller is this even an expected combination?
the args bingding only create advise invoking. see org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory method: public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) ............ if (argNames != null) { springAdvice.setArgumentNamesFromStringArray(argNames); } springAdvice.calculateArgumentBindings(); ............. if you use @Aspect(perthis()) or @Aspect(pertarget) args pointcut expression and need advise method arg binding mode,it will create union pointcut but the second AspectJExpressionPointcut havn't args binding will throw Caused by: java.lang.IllegalArgumentException: warning no match for this type name: ss [Xlint:invalidAbsoluteTypeName]
Comment From: vishalsingh2972
@ZhongGuoDragon were you able to solve this issue, @jhoeller any update on this can we submit a PR on this or is this an internal issue?
Comment From: jhoeller
From my side, there is no concrete plan for this. If someone gets to the bottom of the problem and submits a PR for it, I'm happy to consider it but I'm not actively working on it myself.