Bug 212353

Summary: FindBugs error in abstract aspect that uses pertypewithin - Superclass uses subclass during initialization.
Product: [Tools] AspectJ Reporter: Bhaskar Maddala <maddalab>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: aclement
Version: 1.5.4RC1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Simple eclipse project zipped to reproduce the error none

Description Bhaskar Maddala CLA 2007-12-09 17:00:46 EST
I have an abstract aspect, where I define my point cuts, and 2 derived concrete aspects that use the pointcuts to implement advice. On building in eclipse and running findbugs I get the following bad practice bug

    Superclass uses subclass during initialization.

  I looked at the byte code and I can see that the abstract aspect had references to the concrete aspects. The reason was an overly broad definition of pertypewithin. Below is a toy code sample that results in this findbugs error

package bar;
public abstract aspect AbstractAspect pertypewithin(bar..*) {
    pointcut loginitialization() : staticinitialization(bar..*);
    pointcut loggedMethods() : (within(bar..*)) && execution(* *.*(..));
}

package bar;
public aspect ConcreteAspect extends AbstractAspect {
    after() : loginitialization() {}
    before() : loggedMethods() {}
    after() : loggedMethods() {}
}

The AbstractAspect satisfies the pertypewithin scope and is advised by ConcreteAspect.after():loginitialization

Having a concrete aspect advice a abstract aspect that it inherits seems to be an anti-pattern (at least when using pertypewithin), which is really the reason for FindBugs to be complaining.

Requested Enhancement : Aspectj compiler should report an appropriate warning indicating such a scenario.

Attachment contains a small eclipse project to reproduce the issue.
Comment 1 Bhaskar Maddala CLA 2007-12-09 17:02:03 EST
Created attachment 84818 [details]
Simple eclipse project zipped to reproduce the error
Comment 2 Andrew Clement CLA 2013-06-24 11:06:09 EDT
unsetting the target field which is currently set for something already released