Bug 164573 - [plan] [ataspectj] @AfterReturning advice silently sensitive to order of args() and returning args
Summary: [plan] [ataspectj] @AfterReturning advice silently sensitive to order of args...
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.5.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.6.3   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-15 01:06 EST by Jacques CLA
Modified: 2008-12-05 17:04 EST (History)
1 user (show)

See Also:


Attachments
test code (6.22 KB, application/x-zip-compressed)
2006-11-15 01:09 EST, Jacques CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacques CLA 2006-11-15 01:06:14 EST
---------- SimpleAfterReturningTest.java ---------
package aspects;
public class SimpleAfterReturningTest {
    public Object createBean(String name) {
        return new Object();
    }

    public static void main(String[] args) {
        SimpleAfterReturningTest factory = new SimpleAfterReturningTest();
        System.out.println(factory.createBean("s"));
    }
}


---------- AfterReturningTestAspect.java ------------------
package aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class AfterReturningTestAspect {

    static {
        System.out.println("aspects.AfterReturningTestAspect enabled");
    }

    @AfterReturning(pointcut = "call(Object aspects.SimpleAfterReturningTest.createBean(String)) " +
                            "&& args(beanName)", returning = "bean")
    public void afterReturningCreateBean(JoinPoint joinPoint, String beanName, Object bean) throws Throwable {
        System.out.println("afterReturningCreateBean(JoinPoint joinPoint, String beanName, Object bean) for'" + beanName + "'=" + bean);
    }

    @AfterReturning(pointcut = "call(Object aspects.SimpleAfterReturningTest.createBean(String)) " +
                            "&& args(beanName)", returning = "bean")
    public void afterReturningCreateBean(JoinPoint joinPoint, Object bean, String beanName) throws Throwable {
        System.out.println("afterReturningCreateBean(JoinPoint joinPoint, Object bean, String beanName) for '" + beanName + "'=" + bean);
    }
    
}
-----------------------------------------------------


Gives this output:

aspects.AfterReturningTestAspect enabled
afterReturningCreateBean(JoinPoint joinPoint, Object bean, String beanName) for 's'=java.lang.Object@1690ab
java.lang.Object@1690ab

There is no documentation I found and obviously the LTW has no error message indicating that the returning arg of the advise should be the first parameter of the advise method.
Comment 1 Jacques CLA 2006-11-15 01:09:12 EST
Created attachment 53886 [details]
test code
Comment 2 Andrew Clement CLA 2007-10-26 03:38:56 EDT
look into this for 1.5.4
Comment 3 Andrew Clement CLA 2008-10-02 13:54:45 EDT
one of a few bugs on the similar error of a particular annotation style parameter ordering being required but not enforced until too late. plan them all for 1.6.3
Comment 4 Andrew Clement CLA 2008-12-05 17:04:58 EST
This is worse than the similar case relating to after throwing because of the silent failure.  Due to the weaver picking the wrong parameter for binding, it attempts to cast the return value of the method to String and when it fails the advice doesn't get called.

However, the same fix for after returning also fixes this bug luckily.  We now do better analysis of the parameters and are not sensitive to the ordering.  multiple testcases added.