Bug 126556 - Cannot override super class methods with @DeclareParents
Summary: Cannot override super class methods with @DeclareParents
Status: REOPENED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-06 08:58 EST by Yoav Landman CLA
Modified: 2006-06-02 20:04 EDT (History)
0 users

See Also:


Attachments
aop-test.zip (2.45 KB, application/plain)
2006-02-06 08:59 EST, Yoav Landman CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yoav Landman CLA 2006-02-06 08:58:19 EST
ITD ignores methods from the declared interface implementation if they are already implemented in the super class of the aspected class.

A test case is attached:
Method a() will never be generated into B, since it already implemented in the super class A.
Comment 1 Yoav Landman CLA 2006-02-06 08:59:09 EST
Created attachment 34189 [details]
aop-test.zip
Comment 2 Andrew Clement CLA 2006-02-06 09:11:51 EST
This looks like another case of @AJ decp not behaving like it would if you did it in code style.

Under code style the implementation on the subtype is via ITD

public void B.a() { System.out.println("---a---"); }

and if you do it that way, it works as expected - with the introduced method overriding that in the supertype.
Comment 3 Yoav Landman CLA 2006-02-06 09:43:01 EST
Unfortunately my client is not using Eclipse, so the only option for him is to use @AJ...


Comment 4 Andrew Clement CLA 2006-02-06 11:17:43 EST
I didn't say it wasnt a bug - it is and it needs fixing if thats possible within the current design of @decp.
Comment 5 Adrian Colyer CLA 2006-02-07 03:04:26 EST
Remember that @DeclareParents has declare ... implements  semantics, not declare ... extends. With implements, the given method declaration is treated as a default implementation to be used if the target type does not provide its own.

So the test case is analoguos to the following aspectj program:

public class TestDP extends Super {


  public static void main(String[] args) {
    new TestDP().a();
  }

}


class Super {


  public void a() {
     System.out.println("Super.a");
  }

}

aspect DP {


  interface I { void a(); }

  public void I.a() {
     System.out.println("DP.a");
  }

  declare parents : TestDP implements I;

}

Which raises an interesting semantics issue. The program above fails to compile (!) warning that the ITD conflicts with existing member Super.a(). I don't believe this should be the case - it is not a conflict as we have declare ... implements semantcis. So there is still a bug here...
Comment 6 Wes Isberg CLA 2006-02-17 13:01:29 EST
fwiw, I believe Adrian's code sample *is* a conflict, as defined by the semantics appendix section on point: "Conflicts may occur from ambiguously inheriting members from a superclass and multiple superinterfaces."  It would not be a conflict if the existing implementation were in the target class (target class wins over inherited interface implementation) or if the declaration were on the target class (declaration overrides supertype implementation).  It should also be a conflict if there are declarations of the same member in multiple interfaces implemented by the target class.
Comment 7 Yoav Landman CLA 2006-02-21 20:34:42 EST
I noticed that this bug raises semantic debates, so it has not been assigned yet.
On the practical side, many (arguably, poorly written) 3rd party frameworks, including the framework I needed to use, use null implementations that need be overridden by the developer. I was looking to automate this overriding process with AJ.
Adrian's point of view wrt "implements" semantic seems logical to me since it behaves like normal java code. This is also the approach taken by AspectWerkz mixins (which I  eventually ended up using).
Comment 8 Yoav Landman CLA 2006-06-02 19:48:54 EDT
Works as expected in 1.5.1_a
Comment 9 Yoav Landman CLA 2006-06-02 20:04:54 EDT
My bad (ran wrong tests). Still mismatch between @aj and code style.