Skip to main content

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

Hi Howard

You are only matching method calls in the execution pointcut. You need to add a pattern for constructor execution

e.g.

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


Cheers Chris



Howard Lewis Ship wrote:
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
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Attention:
This email may contain information intended for the sole use of
the original recipient. Please respect this when sharing or
disclosing this email's contents with any third party. If you
believe you have received this email in error, please delete it
and notify the sender or postmaster@xxxxxxxxxxxxxxxxxxxxx as
soon as possible. The content of this email does not necessarily
reflect the views of SolNet Solutions Ltd.



Back to the top