Project: AspectJ
Bug 116626 Load-time weaving - exception from the weaver
Reported: 2005-11-16 03:54:11 | Status: resolved fixed

Hi again :-) I'm trying to use loadtime weaving and getting an exception. Please look at the testcase: Java code: ========== public class Test<T> { Set<T> intsSet; public Test() { this.intsSet = new HashSet<T>(); } public <T> T[] getObjs(T[] a) { return intsSet.toArray(a); } public static void main(String[] args) { System.out.println("AAA :-)"); new TTT().foo(); } } class TTT { public void foo() { Test<Object> mt = new Test<Object>(); Object[] arr = mt.getObjs(new Object[]{}); } } Aspect: ======= public privileged aspect TestAspect { pointcut TestToArray(Test mt) : target(mt) && !within(TestAspect); Object[] around(Test mt, Object[] objs) : TestToArray(mt) && args(objs) && execution(Object[] com.mprv.secsph.Test.getObjs(Object[])) { objs = proceed(mt, objs); System.out.println("GO Aspects!"); return objs; } } aop.xml ======= <aspectj> <aspects> <aspect name="com.mprv.secsph.TestAspect"/> </aspects> <weaver options="-verbose -XlazyTjp -showWeaveInfo"> <include within="com.mprv.*"/> </weaver> </aspectj> Program output: ============== AAA :-) info weaving 'com/mprv/secsph/TestAspect' java.lang.NullPointerException at org.aspectj.weaver.tools.WeavingAdaptor$WeavingClassFileProvider.getBytes (WeavingAdaptor.java:390) at org.aspectj.weaver.tools.WeavingAdaptor.getAtAspectJAspectBytes (WeavingAdaptor.java:259) at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass (WeavingAdaptor.java:181) at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:66) at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform (ClassPreProcessorAgentAdapter.java:52) at sun.instrument.TransformerManager.transform (TransformerManager.java:122) at sun.instrument.InstrumentationImpl.transform (InstrumentationImpl.java:155) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass (SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at com.mprv.secsph.Test.getObjs(Test.java:1) at com.mprv.secsph.TTT.foo(Test.java:34) at com.mprv.secsph.Test.main(Test.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86) GO Aspects! ==== This exception doesn't happen all the time ... but if you will try a few times, you will probably get it. May you can understand what is the problem event without running the test case. Anyway, I took a look at your code, and have a guess (but it's only the guess) - My aspect is in the application classpath. Actually it's in the same package, so may be you are trying to weave the aspect with itself somehow ... Thanks! Misha.

Files changed in fix:
tests/bugs150/pr116626/com/foo/bar/Test.java tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java