Bug 501656 - Problem in abstract @AfterThrowing advice
Summary: Problem in abstract @AfterThrowing advice
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.9   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-18 08:05 EDT by Alexander Kriegisch CLA
Modified: 2016-11-10 18:52 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kriegisch CLA 2016-09-18 08:05:39 EDT
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
Comment 1 Alexander Kriegisch CLA 2016-09-18 08:07:06 EDT
I am confused because the last parameter of this advice
  - *is* named 'exception' and
  - *is* of a subtype of Throwable
Comment 2 Andrew Clement CLA 2016-11-10 17:14:13 EST
I don't imagine the code that checks that hasn't a clue about generics, but taking a deeper look now.
Comment 3 Andrew Clement CLA 2016-11-10 17:27:55 EST
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.
Comment 4 Andrew Clement CLA 2016-11-10 18:52:38 EST
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.