Bug 86938 - Weaved methods that return boolean return false if the return clause contains a boolean expression
Summary: Weaved methods that return boolean return false if the return clause contains...
Status: RESOLVED WORKSFORME
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2.1   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-01 15:01 EST by Ivan Gorgiev CLA
Modified: 2005-10-28 08:01 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 Ivan Gorgiev CLA 2005-03-01 15:01:11 EST
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;
    }
Comment 1 Adrian Colyer CLA 2005-03-08 09:28:26 EST
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.
Comment 2 Adrian Colyer CLA 2005-03-23 09:53:52 EST
for aj5m3 - this is a high priority bug.
Comment 3 Andrew Clement CLA 2005-05-10 03:13:57 EDT
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?
Comment 4 Ivan Gorgiev CLA 2005-05-11 14:03:20 EDT
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
Comment 5 Andrew Clement CLA 2005-09-28 04:13:34 EDT
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?
Comment 6 Andrew Clement CLA 2005-10-28 03:50:12 EDT
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?
Comment 7 Andrew Clement CLA 2005-10-28 08:01:00 EDT
please reopen if you want to progress it.