Search code examples
javaspringannotationsspring-aoppointcut

Why this syntax error in SpringAOP @pointcut not popping any Error?


I am learning SpringAOP, while I am running basic programs I observed strange behaviour from eclipse(of course compiler).

while I am practising on @Pointcut annotation I mistakenly added another parentheses in Pointcut expression..surprisingly I didn't get any error when running.. added to that it's works like charm. It's not even bother about how many round brackets I added at the end..If I change any other syntax in that expression It pops up an Error..

here is syntax error..

 @Pointcut("execution(* com.kish.DAO.*.*(..))))))") 
    public void forPointcut() {}

I used the pointcut expression references for @Before Advices.

@Before("forPointcut()")
public void beforeAddAccountant() {
    System.out.println(" \n----->>>>>  exceuting @Before advice before adding accountant");
}


@Before("forPointcut()")
public void otherLoggers() {
    System.out.println("----->>>>> execution @Pointcut references before methods\n");

}

Can anyone tell me whats happening here?


Solution

  • Yes, I can. The AspectJ pointcut parser is just lenient here, it is as simple as that. This is because it is supposed to be used by the AspectJ compiler, and there we have more thorough checks yielding syntax errors. When used by Spring AOP, though, there are no further checks after parsing because no byte code is generated. The effect is that everything after the first superfluous closing parenthesis is just dumped, e.g.

    execution(* *(..)))))) && !target(java.lang.String)
    

    becomes

    execution(* *(..))
    

    in Spring AOP.

    Please try to stick to correct syntax anyway.