Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] java.lang.StackOverflowError

Hi,

I'm just getting started with AspectJ and am having trouble getting a
simple tracing aspect from "AspectJ in Action" to work correctly.

Here is the complete aspect (which was exactly cut and pasted from the
downloaded source code for the book, with the exception of changing the
aspect's name):

import org.aspectj.lang.*;

public aspect TracerAspect {
    
    pointcut traceMethods() : 
        (execution(* *.*(..))|| execution(*.new(..))) 
        && !within(TracerAspect); 

    before() : traceMethods() && !execution(String *.toString()) {
    	Signature sig = thisJoinPointStaticPart.getSignature();
    	System.err.println("Entering ["
    			   + sig.getDeclaringType().getName() + "."
    			   + sig.getName() + "]"
    			   + createParameterMessage(thisJoinPoint));
    }

    private String createParameterMessage(JoinPoint joinPoint) {
    	StringBuffer paramBuffer = new StringBuffer("\n\t[This: ");
    	paramBuffer.append(joinPoint.getThis());
    	Object[] arguments = joinPoint.getArgs();
    	paramBuffer.append("]\n\t[Args: (");
    	for (int length = arguments.length, i = 0; i < length; ++i) {
    	    Object argument = arguments[i];
    	    paramBuffer.append(argument);
    	    if (i != length-1) {
    	        paramBuffer.append(',');
    	    }
    	}
    	paramBuffer.append(")]");
	    return paramBuffer.toString();
    }
}

The error I get is java.lang.StackOverflowError, with no stack trace.
This sounds like the infinite recursion problem that "!execution(String
*.toString())" was supposed to prevent, I know that the AJIA was written
for AspectJ1.1, and I'm using 1.2, but the documentation said that the
AspectJ language was not changed at all between these two versions, so
I'm not sure what's going on, unless there's an error in the source code
for AJIA.

Does the above aspect look obviously wrong? Are there any differences
between 1.1 and 1.2 that could account for this behavior?

Thanks for any assistance,

Calvin



Back to the top