Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Problems with inverting results from booleanmethods

I've been able to create a reproducible test. My (really pared down) aspect:
 
public aspect LoggingAspect {
 
 pointcut logPointcut() :
  execution (* *.*(..))
  && !within(LoggingAspect);
 
 before() : logPointcut() {
   System.out.println("entering");
 }
 
    after() : logPointcut() {
            System.out.println("exiting");
    }
}
As it only appears in JRockit *while running in WebLogic*, I created a test servlet (below)
As long as there is an after advice, tests 2 and 5 in the servlet return incorrect results.
If I remove it, everything works. Also, if tests 2 and 5 return Boolean objects, it works.
 
It appears AJ not like after advice on methods returning primitives.
Is there a way to bypass them?
 
Randy
 
 
package test;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
 
/**
 * Hello world!
 */
public class TestServlet extends HttpServlet {
 
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        booleanTest(response);
    }
 
    private void booleanTest(HttpServletResponse response) throws ServletException {
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException ioe) {
            throw new ServletException("Could not get writer.");
        }
 
        out.println("Test 1a. Should be false. Was: " + invert1a());
        out.println("Test 1b. Should be true. Was: " + invert1b());
        out.println("Test 2. Should be false. Was: " + invert2());
        out.println("Test 3. Should be true. Was: " + invert3());
        out.println("Test 4. Should be true. Was: " + invert4());
        out.println("Test 5. Should be false. Was: " + invert5());
    }
 
    private boolean invert1a() {
        return ! true;
    }
 
    private boolean invert1b() {
        return ! false;
    }
 
    private boolean invert2() {
        return ! isTrue();
    }
 
    private boolean invert3() {
        return ! isFalse();
    }
 
    private boolean invert4() {
        boolean temp = isFalse();
        return ! temp;
    }
 
    private boolean invert5() {
        boolean temp = isTrue();
        return ! temp;
    }
 
    private boolean isTrue() {
        return true;
    }
 
    private boolean isFalse() {
        return false;
    }
}


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Adrian Colyer
Sent: Monday, June 19, 2006 8:54 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Problems with inverting results from booleanmethods

That sounds like it would be a very serious issue (and a very surprising one!). Do you have any aspects involved or is this reproduceable with straight Java code only? Do you get different results running the exact same byte code on e.g. a sun vm?

Please raise a bug report if this issue is still reproduceable and we can investigate there.
Thanks, Adrian.

On 14/06/06, Stearns, Randy <RStearns@xxxxxxxxxxxxxxxxxx> wrote:

I ran across a situation where an application compiled with iajc 1.5.0 does not return the expected results when running under Jrockit-1.4.2_08.

Example:

public boolean hasChildren() {
    return ! CollectionUtils.isEmpty(children);
}

If isEmptry() returns false, there's no problem, but if it returns true, the method returns true. Also has a problem with ternary operations.

I'm having to use explicit if/else statements.

Has anyone else run across this?

Randy Stearns

****DISCLAIMER
The information contained in this e-mail and attachments, if any, is confidential and may be subject to legal privilege. If you are not the intended recipient, you must not use, copy, distribute or disclose the e-mail and its attachment, or any part of its content or take any action in reliance of it. If you have received this e-mail in error, please e-mail the message back to the sender by replying and then deleting it. We cannot accept responsibility for loss or damage arising from the use of this e-mail or attachments, and recommend that you subject these to your virus checking procedures prior to use

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users





--
-- Adrian
adrian.colyer@xxxxxxxxx ****DISCLAIMER
The information contained in this e-mail and attachments, if any, is confidential and may be subject to legal privilege. If you are not the intended recipient, you must not use, copy, distribute or disclose the e-mail and its attachment, or any part of its content or take any action in reliance of it. If you have received this e-mail in error, please e-mail the message back to the sender by replying and then deleting it. We cannot accept responsibility for loss or damage arising from the use of this e-mail or attachments, and recommend that you subject these to your virus checking procedures prior to use

Back to the top