Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Not matching constructors

I'm trying out some ideas using AspectJ 5.  I'm working in Eclipse
3.1, with the current plugin (1.3.1.2006 etc.).

As an experiment, I'm writing a Defense Coding aspect, that determines
if any method
parameters are null. Further, the check can be defeated at the class
or method/constructor level with an annotation.

My pointcut is matching methods (static and instance) properly:

public aspect CatchNullParameters
{
    pointcut typeNotMarkedAsSuppressed() : !within(@SuppressNullCheck Object+);

    pointcut appliesToClasses() : within(com.howardlewisship.ajexp..*);

    pointcut codeNotMarkedAsSuppressed() : 
execution(!@SuppressNullCheck * *(..));

    pointcut methodsToCheck()  :
        appliesToClasses() &&
        typeNotMarkedAsSuppressed() &&
        codeNotMarkedAsSuppressed();

    before() : methodsToCheck() {
        Object[] args = thisJoinPoint.getArgs();

        for (int i = 0; i < args.length; i++)
        {
            if (args[i] == null)
            {
                String message = String.format(
                        "Parameter #%d passed to method %s (at %s) was null.",
                        i + 1,
                        thisJoinPoint.getSignature().toString(),
                        thisJoinPoint.getSourceLocation());

                System.err.println(message);

                throw new IllegalArgumentException(message);
            }
        }
    }
}

However, I can't seem to get it to apply to my constructors. The
documentation seems to state that execution() matches methods and
constructors, but I'm not seeing it.

Any clues as to what I'm missing?

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com


Back to the top