Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Bug on weaving?

Hello,

I think I have found a bug on the weaving process, related to annotations 
introduction. I don't know exactly how to explain the problem but it seems to 
be something because of the order the compiler does the weaving.

The code is as follows:

Aspect:

public aspect Aspect { 
	 
	declare @method:  
		!@Annotation * (@Annotation *..*).*(..) :  
			@Annotation("introduced"); 
	 
	pointcut anotado(Annotation b) : 
		call(@Annotation * *..*.*(..)) && 
		@annotation(b); 
	 
	pointcut anotadoTopo(Annotation b) : 
		anotado(b) && 
		!cflowbelow(anotado(Annotation)); 
 
	pointcut anotadoNãoTopo(Annotation b, Annotation bTopo) : 
		anotado(b) && 
		cflowbelow(anotadoTopo(bTopo)); 
 
	before(Annotation b, Annotation bTopo) :  
		anotadoNãoTopo(b, bTopo) { 
		out.println("Non-top:"); 
		out.println("\tJoin point: " + thisJoinPointStaticPart); 
		out.println("\tEnclosing join point: " + thisEnclosingJoinPointStaticPart); 
		out.println("\tAnnotation: " + b); 
		out.println("\tTop annotation: " + bTopo); 
	} 
	 
	before(Annotation b) :  
		anotadoTopo(b) { 
		out.println("Top:"); 
		out.println("\tJoin point: " + thisJoinPointStaticPart); 
		out.println("\tEnclosing join point: " + thisEnclosingJoinPointStaticPart); 
		out.println("\tAnnotation: " + b); 
	} 
}

Testing Classes:

public class A { 
 
	@Annotation("A.foo") void foo() { 
		new B().foo(); 
	} 
	public static void main(String[] args) { 
		new A().foo(); 
	} 
 
} 

@Annotation("B") 
public class B { 

	// The Annotation is injected here!
	void foo() { 
	} 
} 

If we use the option "clean" in the menu project, the output is:

Top:
	Join point: call(void teste.A.foo())
	Enclosing join point: execution(void teste.A.main(String[]))
	Annotation: @teste.Annotation(value=A.foo)

Next, if we go to any class, change it and save it, the result is:

Top:
	Join point: call(void teste.A.foo())
	Enclosing join point: execution(void teste.A.main(String[]))
	Annotation: @teste.Annotation(value=A.foo)
Non-top:
	Join point: call(void teste.B.foo())
	Enclosing join point: execution(void teste.A.foo())
	Annotation: @teste.Annotation(value=introduced)
	Top annotation: @teste.Annotation(value=A.foo)

It seems that the before advices are weaved before the ITD of the annotation, 
which means that the before never finds the method annotated (actually, it 
hasn't been annotated before, because it will be so later). Am I right?

Best regards,

Paulo Zenida

P.S. If you haven't understood properly the example, you can find the full 
source in 
https://svn.ci.iscte.pt/aop-tests/strange-feature/WeavingBugs/trunk/ 


Back to the top