Bug 265042

Summary: Around advice don't support covariance
Product: [Tools] AspectJ Reporter: Martin Probst <mail>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: aclement
Version: 1.6.3   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Martin Probst CLA 2009-02-16 12:31:49 EST
If I have these classes:

class A {
  Number foo();
}
class B extends A {
  Integer foo();
}

and I now have this aspect:

aspect X {
  Number around(A a): call(Number A.foo()) && target(a) {
    Number num = proceed();
    return num;
  }
}

I'm going to get an error trying to weave the code. The problem is that there is (apparently) no way to express that the around advice is going to return a different type, depending on the type foo() returns. I.e. in pseudosyntax:

  <T extends Number> T around(A a): call(T A.foo()) && target(a) { ... }
Comment 1 Andrew Clement CLA 2009-02-16 13:04:25 EST
You can generalize the advice to just Object return and it will successfully advise both.  But that is just a workaround.