Community
Participate
Working Groups
Using Sun JDK1.5.0_04 Audit.java public interface Audit { public String getLastUpdatedBy(); public void setLastUpdatedBy(String un); } AuditImpl.java public class AuditImpl implements Audit { private String lastUpdatedBy; public String getLastUpdatedBy() { return lastUpdatedBy; } public void setLastUpdatedBy(String un) { lastUpdatedBy = un; } } TestAspect.java import org.aspectj.lang.annotation.*; Test.java @Aspect public class TestAspect { @DeclareParents("Test") public static Audit introduced = new AuditImpl(); } public class Test { public static void main(String[] args) { Test t = new Test(); Audit a = (Audit)t; a.setLastUpdatedBy("username"); System.out.println("Username ="+a.getLastUpdatedBy()); } } files.lst Audit.java AuditImpl.java TestAspect.java Test.java Compiled using the following command d:\aspectj1.5\bin\ajc -classpath "d:\aspectj1.5\lib\aspectjrt.jar" -argfi le files.lst -1.5 d:\aspectj1.5\bin\aj5 Test Exception in thread "main" java.lang.VerifyError: (class: Test, method: setLastUpdatedBy signature: (Ljava/lang/String;)V) Incompatible argument to function d:\aspectj1.5\bin\aj5 -noverify Test Username=
just my findings: this works fine if you use code style. Any reason why you use 'aj5' to run the program, rather than just 'java Test' - since there is no LTW??
The code style version is public aspect TestAspect { declare parents: Test extends AuditImpl; } After compilation, Test looks like this: public class Test extends AuditImpl{ public Test(); public static void main(java.lang.String[]); } If I compile the annotation style, then Test looks like this: public class Test extends java.lang.Object implements Audit{ public Test(); public static void main(java.lang.String[]); public java.lang.String getLastUpdatedBy(); public void setLastUpdatedBy(java.lang.String); } Looking in 'setLastUpdatedBy' we can see: public void setLastUpdatedBy(java.lang.String); Code: Stack=2, Locals=2, Args_size=2 0: getstatic #64; //Field TestAspect.introduced:LAudit; 3: aload_0 4: invokeinterface #25, 2; //InterfaceMethod Audit.setLastUpdatedBy: (Ljava/lang/String;)V 9: return This is not a static method so aload_0 gets 'this' and attempts to pass it as a String parameter to setLastUpdatedBy(). BANG. The solution is to know whether you are dealing with static methods - and skip 'this' if necessary. Fix checked in, waiting on build.
fix available in AspectJ dev build.
As 'Java -noverify Test' is resulting in jvm crash, I tried with 'aj5'. (In reply to comment #1) > just my findings: this works fine if you use code style. > Any reason why you use 'aj5' to run the program, rather than just 'java Test' - > since there is no LTW??