Community
Participate
Working Groups
---------- 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.
Created attachment 53886 [details] test code
look into this for 1.5.4
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
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.