Community
Participate
Working Groups
What is wrong with this? Am I handling generics wrong or have I hit a bug or limitation in Ajc? package com.myapp; public class ApplicationException extends Exception { private static final long serialVersionUID = 1L; public ApplicationException(String message) { super(message); } } // --------------------------------------------------- package com.myapp.aspect; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import com.myapp.ApplicationException; @Aspect public abstract class ApplicationExceptionHandler<EX extends ApplicationException> { @AfterThrowing( pointcut = "execution(* com.myapp.*.facade.*.*(..))", throwing = "exception" ) public abstract void handleFacadeException(EX exception); } // --------------------------------------------------- Compile error for ApplicationExceptionHandler.aj: the last parameter of this advice must be named 'exception' and be of a subtype of Throwable
I am confused because the last parameter of this advice - *is* named 'exception' and - *is* of a subtype of Throwable
I don't imagine the code that checks that hasn't a clue about generics, but taking a deeper look now.
Actually it looks like it is because there is no local variable table attached to the abstract method so it comes up with a default name of 'arg' which doesn't meet expectations.
Well I didn't know that, or I've forgotten it. Add the argNames="a,b,c" value to the annotation when there cannot be a local variable table (which occurs for abstract methods and non default interface methods). @AfterThrowing( pointcut = "execution(* com.myapp.*.facade.*.*(..))", throwing = "exception", argNames="exception" ) I think this was written before -parameters, which would be another option but needs some code writing in AspectJ to support it. I don't like the duplication, but at least it works.