Bug 117681 - VerifyError when using annotations to define inter-type annotation
Summary: VerifyError when using annotations to define inter-type annotation
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M5   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-23 04:27 EST by Ramana Gundapuneni CLA
Modified: 2005-11-24 04:03 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ramana Gundapuneni CLA 2005-11-23 04:27:13 EST
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=
Comment 1 Andrew Clement CLA 2005-11-23 06:36:56 EST
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??
Comment 2 Andrew Clement CLA 2005-11-23 09:35:18 EST
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.
Comment 3 Andrew Clement CLA 2005-11-23 09:51:17 EST
fix available in AspectJ dev build.
Comment 4 Ramana Gundapuneni CLA 2005-11-24 04:03:22 EST
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??