Results 1 to 6 of 6

Thread: argument binding failure when passing parameter to advice

  1. #1
    Join Date
    Sep 2005
    Location
    St. Louis, MO USA
    Posts
    25

    Default 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. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    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);
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Sep 2005
    Location
    St. Louis, MO USA
    Posts
    25

    Default

    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[])
    .

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I think you missed a ')' in you pointcut expression

    Code:
    @Pointcut("execution(* getPrivilegedPersonnel(java.util.List, ..) && args(privs, ..))")
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2005
    Location
    St. Louis, MO USA
    Posts
    25

    Default

    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)

  6. #6
    Join Date
    Sep 2005
    Location
    St. Louis, MO USA
    Posts
    25

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •