Bug 58567 - Compiler weaves advice wrongly if the core logic of a method is invoked within a return statement
Summary: Compiler weaves advice wrongly if the core logic of a method is invoked withi...
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-14 17:29 EDT by Manoj K. Gupta CLA
Modified: 2004-10-21 04:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Manoj K. Gupta CLA 2004-04-14 17:29:12 EDT
Consider the method below:

public int add(int x, iny){
return x+y;
}

If I write an after advice for this method, then after advice is weaved before 
the return statement. 

I am not sure, I will call a bug, but it is definitely a problem
Comment 1 Andrew Clement CLA 2004-04-20 11:20:07 EDT
I'm interested in how you believe the advice is being woven before the return -
 are you executing a program or are you merely looking at decompiled .class 
files?

Here is my example program that I think would give a strange answer if after 
advice was being applied before the return statement:

public class IsAfterAfterOrBefore {
	
  static int thingy = 1;
	
  public int increaseMe(int x){
    return x+thingy;
  }
  
  public static void main(String[] args) {
  	IsAfterAfterOrBefore inst = new IsAfterAfterOrBefore();
  	int result = inst.increaseMe(3);
	System.err.println(result);
  }
} 

aspect Interference {
	after() returning: execution(* increaseMe(..)) {
		IsAfterAfterOrBefore.thingy = 2;
	}
}

So, if after advice is applied correctly, after the return statement then I 
get the output '4' and indeed that is what I get when I run this program.  If 
the advice was running before the return statement executed then it would 
erroneously output '5'.

However, if you happen to decompile the output of this program, it shows this:

    public int add(int x)
    {
        Interference.aspectOf().ajc$afterReturning$Interference$1$49aefe4d();
        return x + thingy;
    }

    public static void main(String args[])
    {
        IsAfterAfterOrBefore inst = new IsAfterAfterOrBefore();
        int result = inst.add(3);
        System.err.println(result);
    }

which makes you *think* the advice is executing before the return statement - 
I believe the decompiler is not giving you a true picture of what is occurring 
in the bytecode.

Can you confirm how you are seeing this problem, possibly by giving me a 
complete test program that shows it misbehaving?

thanks.
Comment 2 Adrian Colyer CLA 2004-08-06 08:32:31 EDT
Closing this one out. There are plenty of test cases in the suite that would soon start complaining if the 
implementation of after advice was incorrect. Since there have been no comments for several months I 
presume there is no real  bug here - please re-open if this is not the case.
Comment 3 Adrian Colyer CLA 2004-10-21 04:32:48 EDT
Fix released as part of AspectJ 1.2.1