Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Runtime weaving of Java API classes - newbie question!

Hello All,

I am trying to weave some precompiled aspects into classes loaded into the JVM using the org.aspectj.weaver.WeavingURLClassLoader as demonstrated in the aj script. However, the weaving seemed to exclude Java API classes, although my own classes are correctly woven.

For example given the following pointcut:

pointcut write(Object data) : call (* java.io.*File*+.write(..)) && args(data,..);

and given the following code snippet

//----------------------
	 import java.io.*;
	 // other class codes	
	
	 FileOutputStream file = new FileOutputStream("Test");
	 ObjectOutputStream file2 = new ObjectOutputStream(file);

	 file.write(1);
	 file2.write(2);
	
//----------------------		
	

Observation:

file.write(1); gets "caught" by the pointcut but not file2.write(2); even though the ObjectOutpuStream.write(int) method calls the FileOutputStream.write(int) method - according to the API specs. The behaviour I wanted was to have a trigger on the FileOutputStream.write() method, for example, regardless of whether my code called it or one of the Java API codes.
 	
My assumption is that because the Java boot ClassLoader loads the Java APIs classes, org.aspectj.weaver.WeavingURLClassLoader does not get an opportunity to weave them. If this is correct, then how do I get to instrument rt.jar classes at runtime/loadtime? Or is there another way to let these classes "pass" through WeavingURLClassLoader for instrumentation? Maybe there is a much better approach.

I am a newbie, please pardon my ignorance if I have completely lost the plot!

Thanks,

Dayo



Back to the top