Community
Participate
Working Groups
Hi, When I use the WeavingAspect from aspectjtool.jar and apply the following aspect to a class with methods that has an argument using generics, the weaving fails. This happens only for the after() advice (the before() advise works fine). This is the class: import java.lang.reflect.*; public class MyArray { public static <T> T[] test(T[] original, int newLength ,Class<? extends T[]>newType) { T[]copy = (T[])Array.newInstance(original.getClass().getComponentType(),newLength); return copy; } } This is the aspect: mport org.aspectj.lang.*; public final aspect TraceAspect { static final pointcut allExecs() : (execution(* *(..)) || execution(*.new(..))); static private JoinPoint.StaticPart _discovered = null; after(): allExecs() { _discovered = null; } } The same problem occurs even if the method does nothing (so I really think it is related to the argument type).. import java.lang.reflect.*; public class MyArray2 { public static <T> T[] test(Class<? extends T[]>newType) { return null; } } Here is what WeavingAdaptor.weave() gives as exception: org.aspectj.bridge.AbortException: trouble in: public class MyArray2 extends java.lang.Object: public void <init>(): ALOAD_0 (line 2) INVOKESPECIAL java.lang.Object.<init> ()V constructor-execution(void MyArray2.<init>()) | catch java.lang.Throwable -> E0 | | GOTO L0 | catch java.lang.Throwable -> E0 | E0: ASTORE_1 | INVOKESTATIC TraceAspect.aspectOf ()LTraceAspect; | INVOKEVIRTUAL TraceAspect.ajc$after$TraceAspect$1$4431da2 ()V | ALOAD_1 | ATHROW | L0: INVOKESTATIC TraceAspect.aspectOf ()LTraceAspect; | INVOKEVIRTUAL TraceAspect.ajc$after$TraceAspect$1$4431da2 ()V | RETURN constructor-execution(void MyArray2.<init>()) end public void <init>() public static Object[] test(Class): method-execution(java.lang.Object[] MyArray2.test(java.lang.Class)) | catch java.lang.Throwable -> E0 | | ACONST_NULL (line 5) | | ARETURN | catch java.lang.Throwable -> E0 | E0: ASTORE_1 | INVOKESTATIC TraceAspect.aspectOf ()LTraceAspect; | INVOKEVIRTUAL TraceAspect.ajc$after$TraceAspect$1$4431da2 ()V | ALOAD_1 | ATHROW method-execution(java.lang.Object[] MyArray2.test(java.lang.Class)) end public static Object[] test(Class) end public class MyArray2 This does not occur when I use ajc on the command line... This is the code generated by ajc, which seems to be correct. (I use javap) Compiled from "MyArray2.java" public class MyArray2 extends java.lang.Object{ public MyArray2(); Signature: ()V Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: goto 16 7: astore_1 8: invokestatic #22; //Method TraceAspect.aspectOf:()LTraceAspect; 11: invokevirtual #25; //Method TraceAspect.ajc$after$TraceAspect$1$4431da2:()V 14: aload_1 15: athrow 16: invokestatic #22; //Method TraceAspect.aspectOf:()LTraceAspect; 19: invokevirtual #25; //Method TraceAspect.ajc$after$TraceAspect$1$4431da2:()V 22: return Exception table: from to target type 4 7 7 Class java/lang/Throwable public static java.lang.Object[] test(java.lang.Class); Signature: (Ljava/lang/Class;)[Ljava/lang/Object; Code: 0: aconst_null 1: astore_2 2: goto 14 5: astore_1 6: invokestatic #22; //Method TraceAspect.aspectOf:()LTraceAspect; 9: invokevirtual #25; //Method TraceAspect.ajc$after$TraceAspect$1$4431da2:()V 12: aload_1 13: athrow 14: invokestatic #22; //Method TraceAspect.aspectOf:()LTraceAspect; 17: invokevirtual #25; //Method TraceAspect.ajc$after$TraceAspect$1$4431da2:()V 20: aload_2 21: areturn Exception table: from to target type 0 5 5 Class java/lang/Throwable } This problem occurs with the WeavingAdaptor of 1.5.3, 1.5.4 and the development versions Thanks, Alex
The code supplied here is now compiling with the latest dev builds of AspectJ. The Array type was changed to a ReferenceType subclass from its original, simpler, ResolvedType subclass. This removed any chance of ClassCastExceptions occuring when the bound of a declaration was an array, like: Class<? extends T[]> Since bounds are always treated as ReferenceTypes. thanks for the clear test program.