Bug 36787 - interface initializer order is wrong
Summary: interface initializer order is wrong
Status: REOPENED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 2000
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-23 04:44 EDT by George Harley CLA
Modified: 2009-08-30 02:49 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description George Harley CLA 2003-04-23 04:44:22 EDT
I am using AspectJ 1.1rc1. Here is my simple test case...

public class Inner1
{}

public class Inner2 extends Inner1
{}

public interface NewInterface
{}

public class Outer extends Inner2 implements NewInterface
{
  public static void main(String[] args)
  {
    Outer outer = new Outer();
  }
}

public aspect InitAspect
{
  pointcut outerMatch() : initialization(new(..));
  before() : outerMatch()
  {
    System.out.println(thisJoinPoint.toLongString());
  }
}

As I understand it, the outerMatch() pointcut will match all constructors in the 
system. The above all compiles nicely but when I run Outer I get the following 
(please ignore line numbers) ...
java.lang.ExceptionInInitializerError: org.aspectj.lang.NoAspectBoundException
  at InitAspect.aspectOf(InitAspect.java)
  at InitAspect.<init>(InitAspect.java:14)
  at InitAspect.ajc$postClinit(InitAspect.java)
  at InitAspect.<clinit>(InitAspect.java:14)
  at Inner1.<init>(Inner1.java:14)
  at Inner2.<init>(Inner2.java:14)
  at Outer.<init>(Outer.java:14)
  at Outer.main(Outer.java:18)
  Exception in thread "main" 

If I compile the above system with AspectJ 1.0 before running Outer then it all 
works and I see the following output ...
initialization(public Inner1())
initialization(public Inner2())
initialization(public NewInterface())
initialization(public Outer())

It would appear that the pointcut is matching the InitAspect itself. The only 
way I can get my simple test case to work with 1.1rc1 is to modify my 
outerMatch() pointcut to explicitly remove the aspect from the scope ...

pointcut outerMatch() : initialization(new(..)) && !within(InitAspect);

When I run this I get the following output (note the subtle change in the order 
of the matches compared to what I got using AspectJ 1.0 - now the interface 
match comes after the Outer match)....
initialization(public Inner1())
initialization(public Inner2())
initialization(public Outer())
initialization(public NewInterface())

Is this behaviour a 1.1 bug or was 1.0 behaving incorrectly ?
Comment 1 Jim Hugunin CLA 2003-04-24 17:24:15 EDT
The NoAspectBoundException is a correct change in AspectJ-1.1 and is 
documented in the readme:
  http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/README-
11.html#ASPECT_INSTANTIATION_AND_ADVICE

The order of the interface initializers you're seeing is a bug, but I don't 
believe it is critical, so I'm leaving it as a P3.  If it turns out to be easy 
to fix it should be resolved for 1.1rc2.
Comment 2 Jim Hugunin CLA 2004-01-30 18:10:51 EST
A test case has been added to ajcTestsFailing.xml.

The 1.2 target milestone has been removed.  After analysis, this bug is tightly
coupled with the implementation of initialization join points.  This 
implementation is complicated and I'm very wary of changing it to fix a bug 
this small.
Comment 3 Adrian Colyer CLA 2005-08-26 10:59:01 EDT
We're not going to get to this in AJ 1.5.0. Marking as "LATER" for consideration
in 1.5.1 and future release planning. 

No-one else has run into this issue that I'm aware of in the 2.5 years since it
was first raised so this is not a high-priority problem right now.
Comment 4 Eclipse Webmaster CLA 2009-08-30 02:49:38 EDT
LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated.