0

I have defined an Aspect with the following pointcut

pointcut transactedMethod() : TransactionBoundary.transactedMethod();

This is an alias created for all transactional methods with some error raised if proper exception is not raised.

    public aspect TransactionBoundary {

     declare error :
        execution(* *..*.transacted*(..) throws !SQLException)
        : "A transacted method must throw SQLException";
     
        pointcut transactedMethod() :
            execution (* *..*.transacted*(..) throws SQLException);    
    }

and an around advice like below Object around() throws SQLException : transactedMethod()

In my code, this works for all methods with signature as transactedInsert(), transactedUpdate()but not for methods with names as transactedOrderInsert()

Is there some issue or something that I am overlooking. Any specific reason why this will not work with method signatures like transactedOrderInsert()? And if it will, what could be the reason that it does not work for me?

  • This code snippet is useless because it does not show the actual root pointcut. The syntax of `TransactionBoundary.transactedMethod()` suggests that you are referring to another pointcut from this one, basically aliasing it. Actually, the alias is the same pointcut name again, just in (hopefully) another aspect class. Quite strange, why would you do that? Anyway, please show the content of the `TransactionBoundary.transactedMethod()` pointcut, so I can see what that one is targeting. – kriegaex Jul 09 '20 at 08:14
  • @kriegaex thanks for looking into it. I missed out the root pointcut and I have now updated the ticket with the details. However, it seems that it should work for all methods where the name starts with transacted - I would then need to check why this is not working for specific cases. – Vikash Jain Jul 09 '20 at 08:33
  • Actually your pointcut looks okay, even though more complicated than necessary. You can shorten "any class in any package" from `*..*.*` to just `*..*`. Actually, if you do not care about class and package name at all, you can just write `execution (* transacted*(..) throws SQLException)`. But that is not the problem, I am just mentioning it. – kriegaex Jul 09 '20 at 08:40
  • Something must be different about `transactedOrderInsert()` from the methods which are actually intercepted. As you are not sharing a full [MCVE](https://stackoverflow.com/help/mcve), I cannot reproduce your problem. I cannot see the target class(es) and method(s) you are having problems with. Is the non-intercepted method in the very same class as another methods which is intercepted successfully? I am not a psychic, so I cannot read your code from here. ;-) – kriegaex Jul 09 '20 at 09:02

0 Answers0