Bug 166647 - java.lang.NoSuchFieldError when using cflow in pointcut declaration with LTW
Summary: java.lang.NoSuchFieldError when using cflow in pointcut declaration with LTW
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.5.3RC1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.6.3   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-04 11:04 EST by Mario Gleichmann CLA
Modified: 2008-12-09 15:57 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Gleichmann CLA 2006-12-04 11:04:43 EST
When using LTW and having a pointcut declaration that's using cflow, the VM exits with an exception: java.lang.NoSuchFieldError: ajc$cflowCounter$0

This behaviour may be similar to reported bugs #149096 and Bug #132080 (should be fixed), but even with 1.5.3, the mentioned exception occurs.

Here's an example, that reproduces the exception with AspectJ 1.5.3 (using eclipse):

1.) /META-INF/aop.xml:

<?xml version="1.0"?>
<aspectj>
  <aspects>
    <aspect name="net.test.ltw.aspect.LoggingAspect"/>
  </aspects>
  <weaver>
    <exclude within="org.apache..*"/>
    <include within="net.test.ltw.beans..*"/>
  </weaver>
</aspectj>

2.) The Aspect, using cflow:

package net.test.ltw.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class LoggingAspect {
	
	@Pointcut("execution(* sayHello(..)) "
           + " && !cflow( execution( *   
                   net.test.ltw.beans.caller.EvilWorldCaller.callWorld(..) ) ) "
	)
	public void sayHelloExecutions() {}
	
	@Around("sayHelloExecutions()")
	public Object validateMethodCall( ProceedingJoinPoint joinPoint ) throws Throwable{

		System.out.println( "---" ) ;
		System.out.println( "entry " + joinPoint.toLongString() );
		
		Object retVal = joinPoint.proceed();
		
		System.out.println( "exit " + joinPoint.toLongString() );
		
		return retVal;
	}
}

3.) The beans to advice:

package net.test.ltw.beans.caller;

import net.test.ltw.beans.worlds.World;

public class GoodWorldCaller {

	World world = new World();
	
	public void callWorld(){
		world.sayHello();
	}
}

and 

package net.test.ltw.beans.caller;

import net.test.ltw.beans.worlds.World;

public class EvilWorldCaller {

	World world = new World();
	
	public void callWorld(){
		world.sayHello();
	}
}

4.) The Main, starting the Example:

package net.test.ltw.beans.caller;

public class CallerMain {

	public static void main(String[] args) {

		GoodWorldCaller goodWorldCaller = new GoodWorldCaller();
		EvilWorldCaller evilWorldCaller = new EvilWorldCaller();
		
		goodWorldCaller.callWorld();
		evilWorldCaller.callWorld();
	}

}

5.) The VM is startet with VM-Arg 

-javaagent:D:\Temp\mvel\AspectJ-1.5.3_INVEST\lib\aspectjweaver.jar


Greetings

Mario
Comment 1 Mario Gleichmann CLA 2006-12-04 11:08:05 EST
Here's the full stacktrace:

Exception in thread "main" java.lang.NoSuchFieldError: ajc$cflowCounter$0
	at net.test.ltw.beans.worlds.World.sayHello(World.java)
	at net.test.ltw.beans.caller.GoodWorldCaller.callWorld(GoodWorldCaller.java:10)
	at net.test.ltw.beans.caller.CallerMain.main(CallerMain.java:10)
Comment 2 Matthew Webster CLA 2006-12-05 10:56:39 EST
I think you might be experiencing the same incremental compilation bug that I saw last week. You code works for me (with the addition of World.java):

package net.test.ltw.beans.caller;

public class World {

	public void sayHello () {
		System.out.println("Hello");
	}
}

and using a generated aop-ajc.xml and some weaver options in my own aop.xml

<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
	<weaver options="-verbose -showWeaveInfo"/>
</aspectj>

I got the following

[AppClassLoader@92e78c] info AspectJ Weaver Version 1.5.3 built on Wednesday Nov 22, 2006 at 11:18:15 GMT
[AppClassLoader@92e78c] info register classloader sun.misc.Launcher$AppClassLoader@92e78c
[AppClassLoader@92e78c] info using configuration /C:/workspaces/temp/Mario_Gleichmann/bin/META-INF/aop.xml
[AppClassLoader@92e78c] info using configuration /C:/workspaces/temp/Mario_Gleichmann/bin/META-INF/aop-ajc.xml
[AppClassLoader@92e78c] info register aspect net.test.ltw.aspect.LoggingAspect
[AppClassLoader@92e78c] weaveinfo Join point 'method-execution(void net.test.ltw.beans.caller.World.sayHello())' in Type 'net.test.ltw.beans.caller.World' (World.java:6) advised by around advice from 'net.test.ltw.aspect.LoggingAspect' (LoggingAspect.java) [with runtime test]
---
entry execution(public void net.test.ltw.beans.caller.World.sayHello())
Hello
exit execution(public void net.test.ltw.beans.caller.World.sayHello())
Hello

ARe you using AJDT? Try cleainng your project.
Comment 3 Telmo CLA 2007-08-15 12:52:48 EDT
I had a similar problem with LTW and cflow pointcut, so I tried using the example in this bug. I tested the example with the changes from Matthew Webster and the problem happens for me...

I´m using eclipse 3.3, jdk1.5.0_10 and aspectj 1.5.3. I have AJDT installed but for this test I´m using a pure java project.

I got the following output:


[AppClassLoader@92e78c] info AspectJ Weaver Version 1.5.3 built on Wednesday Nov 22, 2006 at 11:18:15 GMT
[AppClassLoader@92e78c] info register classloader sun.misc.Launcher$AppClassLoader@92e78c
[AppClassLoader@92e78c] info using configuration /D:/projetos/aop-test/bin/META-INF/aop.xml
[AppClassLoader@92e78c] info register aspect net.test.ltw.aspect.LoggingAspect
[AppClassLoader@92e78c] weaveinfo Join point 'method-execution(void net.test.ltw.beans.caller.World.sayHello())' in Type 'net.test.ltw.beans.caller.World' (World.java:6) advised by around advice from 'net.test.ltw.aspect.LoggingAspect' (LoggingAspect.java) [with runtime test]
Exception in thread "main" java.lang.NoSuchFieldError: ajc$cflowCounter$0
	at net.test.ltw.beans.caller.World.sayHello(World.java)
	at net.test.ltw.beans.caller.GoodWorldCaller.callWorld(GoodWorldCaller.java:10)
	at net.test.ltw.beans.caller.CallerMain.main(CallerMain.java:10)


I tried using before and after advice but the problem seems to persist...

Bug #186322 may be a similar issue?
Comment 4 Dan Cimpoesu CLA 2007-08-31 01:34:21 EDT
My testing shows that this bug is still present in version org.aspectj.runtime_1.5.4.200705211336 / org.aspectj.weaver_1.5.4.200705211336.

Is there any action to fix this bug?

Thanks
Dan

Comment 5 Andrew Clement CLA 2007-11-06 12:16:58 EST
as I described just now in bug 186322 - we have effectively given our users some rope and they've hung themselves....  it is working as designed but you are tripping over something that is not at all obvious and I need to address it.

The problem is that the aspect is 'incomplete' until woven and does not contain the cflow field that is required.  Your aop.xml says:

<weaver>
    <exclude within="org.apache..*"/>
    <include within="net.test.ltw.beans..*"/>
</weaver>

and that excludes the aspect itself - so it cannot be woven and the cflow field does not get added.  Changing the aop.xml to include the aspect class:

<weaver>
    <exclude within="org.apache..*"/>
    <include within="net.test.ltw.beans..*"/>
    <include within="net.test.ltw.aspect..*"/>
</weaver>

causes everything to work perfectly.

Comment 6 Andrew Clement CLA 2007-12-04 04:42:04 EST
To address this cryptic failure, the weaver now produces this kind of error if you exclude the XML aspect from weaving.

[WeavingURLClassLoader] error XML Defined aspects must be woven in cases where cflow pointcuts are involved. Currently the include/exclude patterns exclude 'x.Aspect2'

A proper solution would force it to be included but only apply the relevant mungers to it - but that is more work than I have time for before 1.5.4.  If I force it to be included now then it will get affected by all other aspects that are around and there will be nothing the user can do to stop that happening.
Comment 7 Andrew Clement CLA 2007-12-04 04:43:01 EST
The changes are in 1.5.4 for the error message but I am not closing this until the proper solution is done, so moving to 1.6.0
Comment 8 Andrew Clement CLA 2008-08-26 23:08:26 EDT
this hasn't arisen again as a problem since I put in the message - so reducing priority
Comment 9 Andrew Clement CLA 2008-12-09 15:57:03 EST
as per bug 186322 - closing this as the message has seemed to be sufficient.  it hasnt come up again since that message was included in a release.