Announcement Announcement Module
Collapse
No announcement yet.
argument binding failure when passing parameter to advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • argument binding failure when passing parameter to advice

    I'm trying to use Spring 2.0 and the AspectJ annotations to write an aspect using Spring. I have the following Aspect defined :

    Code:
    @Aspect
    public class PersonnelAspect {
    
         @Pointcut("execution(* getPrivilegedPersonnel(java.util.List, ..) && args(privs, ..)")
         public void privilegedPersonnel(List privs) {}
    
    	@Around("privilegedPersonnel(privs)")
    	public Object protectPersonnel(ProceedingJoinPoint thisJoinPoint, List privs) throws Throwable {
    		if(ok()) {
    			return thisJoinPoint.proceed(new Object[]{privs});
    		} else {
                            //call a different method with the privs parameters
    			return anotherMethod(privs);
    		}
    	}
    }
    When I startup, I am getting this error :

    Caused by: java.lang.IllegalStateException: Failed to bind all argument names: 1 argument(s) could not be bound
    at org.springframework.aop.aspectj.AspectJAdviceParam eterNameDiscoverer.getParameterNames(AspectJAdvice ParameterNameDiscoverer.java:262)
    at org.springframework.core.PrioritizedParameterNameD iscoverer.getParameterNames(PrioritizedParameterNa meDiscoverer.java:54)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.bindArgumentsByName(AbstractAspectJAdvice.java :370)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.calculateArgumentBindings(AbstractAspectJAdvic e.java:331)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.afterPropertiesSet(AbstractAspectJAdvice.java: 297)
    at org.springframework.aop.aspectj.annotation.Reflect iveAspectJAdvisorFactory.getAdvice(ReflectiveAspec tJAdvisorFactory.java:216)


    I stepped through AspectJAdviceParameterNameDiscoverer.getParameterN ames(Method method) and noticed that its looking for @args? This doesn't make sense to me, am i missing something?

    Thanks,
    Dave

  • #2
    This sounds like a bug that has been fixed in 2.0.1. Please try with that version.

    Also, you should be able to simply the call to proceed. Instead of
    Code:
    thisJoinPoint.proceed(new Object[]{privs});
    use
    Code:
    thisJoinPoint.proceed(privs);

    Comment


    • #3
      I upgraded to Spring 2.0.1 and I'm still getting the same errors.

      I've gone over the pointcut definition again and it seems to be syntactically correct, so I don't know what I could be missing.

      Also I looked at the
      Code:
      thisJoinPoint.proceed(new Object[]{privs})
      call and the only method defined is
      Code:
      proceed(Object[])
      .

      Comment


      • #4
        I think you missed a ')' in you pointcut expression

        Code:
        @Pointcut("execution(* getPrivilegedPersonnel(java.util.List, ..) && args(privs, ..))")

        Comment


        • #5
          You we're right I was missing a following parenthesis after the execution call
          Code:
          execution(* getPrivilegedPersonnel(java.util.List, ..)) && args(privs, ..)
          But I'm still getting the same argument bind error :

          Caused by: java.lang.IllegalStateException: Failed to bind all argument names: 1 argument(s) could not be bound
          at org.springframework.aop.aspectj.AspectJAdviceParam eterNameDiscoverer.getParameterNames(AspectJAdvice ParameterNameDiscoverer.java:282)
          at org.springframework.core.PrioritizedParameterNameD iscoverer.getParameterNames(PrioritizedParameterNa meDiscoverer.java:54)
          at org.springframework.aop.aspectj.AbstractAspectJAdv ice.bindArgumentsByName(AbstractAspectJAdvice.java :356)
          at org.springframework.aop.aspectj.AbstractAspectJAdv ice.calculateArgumentBindings(AbstractAspectJAdvic e.java:317)
          at org.springframework.aop.aspectj.AbstractAspectJAdv ice.afterPropertiesSet(AbstractAspectJAdvice.java: 283)
          at org.springframework.aop.aspectj.annotation.Reflect iveAspectJAdvisorFactory.getAdvice(ReflectiveAspec tJAdvisorFactory.java:211)

          Comment


          • #6
            I've been doing some digging and this is what I've found.

            Here's some rough pseudo code from the Spring class AspectJAdviceParameterNameDiscoverer.maybeBindThis OrTargetOrArgsFromPointcutExpression() when it parses the Aspect I pasted above :

            Code:
            AspectJAdviceParameterNameDiscoverer.maybeBindThisOrTargetOrArgsFromPointcutExpression() {
                 String pointcutExpression = "privilegedPersonnel(privs)";
                 if(pointcutExpression matches "this" or "target") {
                      parse variable name & add to varNames
                 } else if(pointcutExpression matches "args") {
                      extract and set variable arguments from pointcut body
                 }
            }
            The issue is that I'm defining the pointcut with the following :
            Code:
            	@Pointcut("execution(* getPrivilegedPersonnel(java.util.List, ..)) && args(privs, ..)")
            	public void privilegedPersonnel(List privs) {}
            and then I'm defining the advice like this :
            Code:
            	@Around("privilegedPersonnel(privs)")
            	public Object protectPersonnelBodUsage(ProceedingJoinPoint thisJoinPoint, List privs) throws Throwable { ..... }
            Notice that the AspectJAdviceParameterNameDiscoverer class is expecting the args(...) declaration to be in the actual @Around declaration vs. the @Pointcut declaration. As far as I know the way I've defined my @Pointcut is valid in AspectJ.

            The question then becomes, Does Spring require the args(...) declaration to be in the "Advice" declaration (e.g. @Around("privilegedPersonnel(privs) && args(...)")?

            If not then the code in AspectJAdviceParameterNameDiscoverer needs to be enhanced so it can account for the args(...) declaration in @Pointcut.

            Comment

            Working...
            X