I am trying to set a pointcut to a private java.net.AbstractSocketImpl.connectToAddress (..) method and I want to use a temporary weave. This is my test code:
public class Main { public static void main(String args[]) throws Throwable { new java.net.Socket("localhost", 10111); } }
and this is my preferred aspect:
privileged aspect PrivAspect { before() : call(* java.net.AbstractPlainSocketImpl.connectToAddress(..)) { System.out.println("It works"); } }
and this is META-INF / aop.xml
<aspectj> <aspects> <aspect name="PrivAspect"/> </aspects> <weaver options="-verbose -Xset:weaveJavaPackages=true"/> </aspectj>
This is how I compile the code:
$ javac Main.java $ java -jar ../lib/aspectjtools-1.6.11.jar -source 6 -cp .:$CLASSPATH PrivAspect.aj [warning] this affected type is not exposed to the weaver: java.net.AbstractPlainSocketImpl (needed for privileged access) [Xlint:typeNotExposedToWeaver] /home/batto/work/ajtest/test/PrivAspect.aj:2 [warning] advice defined in PrivAspect has not been applied [Xlint:adviceDidNotMatch] 2 warnings $ java -cp .:$CLASSPATH -javaagent:../lib/aspectjweaver-1.6.11.jar Main
The last line throws the expected exception "refused" (port is closed), but the tip is not called.
What is the problem?
Thanks.
EDIT: I know that java.net.AbstractPlainSocketImpl.connectToAddress (..) is being called (I was debugging Main in Eclipse).
batto source share