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

This is a great piece of detective work, thanks. Given the circumstances needed to reproduce (must be JRockit, must be running in WLS), my suspicions are that we're seeing a bug in the JRockit JIT when it's running in server mode (the JVM gets different switches passed to it under WLS than on the command line). The bug is no doubt triggered by a bytecode pattern that AspectJ is generating. Still, first I want to be 100% sure that AspectJ is not doing anything incorrect before we go that route.

I've raised bug 148007 to cover this (https://bugs.eclipse.org/bugs/show_bug.cgi?id=148007). Please could you append to that bug report details of the exact WLS, JRockit, and AspectJ versions you are using, and also details of the AspectJ compiler options you used to compile this simple example. In fact, to be doubly sure I'm staring at the right thing, if you could attach your .class files for LoggingAspect and TestClass that would be really helpful too.

As a workaround, you can avoid advising methods that return primitives by changing your logPointcut as follows:

pointcut logPointcut() :
  execution(Object+ *.*(..))
  && !within(LoggingAspect);

that's certainly not a workaround we'd want anyone to have to use for real!

On 21/06/06, Stearns, Randy < RStearns@xxxxxxxxxxxxxxxxxx> wrote:
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

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





--
-- Adrian
adrian.colyer@xxxxxxxxx

Back to the top