Community
Participate
Working Groups
When a boolean method implementation has an expression on its 'return' statement line the method woven with around advice always returns 'false', even when it should return 'true'. Here is an example: public boolean hasReferenceRelationship(String referenceRelationship) { return (referenceRelationships.get(referenceRelationship) != null); } The referenceRelationships instance variable is a HashMap and it does contain a non-null value for the key represented by referenceRelationship parameter's value. Changing the method code to the following makes the method work as expected: public boolean hasReferenceRelationship(String referenceRelationship) { Object refRelationship = referenceRelationships.get(referenceRelationship); boolean hasRelationship = (refRelationship != null); return hasRelationship; }
AMC notes: I remember seeing something similar to this before... if we haven't already fixed it in AspectJ 5 then this should be a high priority bug. Moving to P1.
for aj5m3 - this is a high priority bug.
I can't get this to fail for me, here is my program: import java.util.*; aspect PR86938 { static Hashtable list = new Hashtable(); public static boolean ret() { return (list.get("andy")!=null); } public static void main(String[]argv) { System.err.println("Answer is: "+ret()); list.put("andy","1"); System.err.println("Answer is now: "+ret()); } boolean around(): execution(* ret(..)) { boolean b= proceed(); System.err.println("Returning: "+b); return b; } } And here is the output when I run it: Returning: false Answer is: false Returning: true Answer is now: true I've tried call instead of execution in the advice, I've tried -XnoInline. Sorry its taken a while to get round to looking at this - do you have a more complete standalone example that shows the problem?
Andy, I don't have an example that is business logic-free. I'll try to come up with one when schedule allows. One thing worth mentioning is that my advised code is in a separate class from the advice itself, as opposed to your test case, which has both in the same class. Don't know if that matters but might be worth trying out. Ivan
Is this scenario still failing for you? Without a testcase I can't work on it - it just doesnt fail for me. Can you tell me whats in your around advice (in case that affects it) - do you have multiple proceeds? How is it different to my around advice?
I'm going to have to defer or close this one, it just doesn't happen for me and this is the only bug report that it happens. If you want me to progress it, can you send me (via private email as its no doubt sensitive) the class file that exhibits the strange behavior?
please reopen if you want to progress it.