[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [aspectj-users] Question about constructor pointcuts
- From: Simone Gianni <simoneg@xxxxxxxxxx>
- Date: Wed, 26 Nov 2008 13:51:52 +0100
- Delivered-to: firstname.lastname@example.org
- User-agent: Thunderbird 22.214.171.124 (X11/20070310)
every method/constructor will be trapped if using the execution
pointcut, because in that case the advice code is inlined IN the
method/constructor, so it doesn't matter if reflection or direct call is
used the advice will be executed.
But when using the call pointcut, AspectJ is not able to determine to
which method/constructor of which class is being called by a reflection
based call, because it would be determined at runtime and not statically.
So, yes, what you say is right when using execution pointcut,
unfortunately it is not when using call pointcut.
There are quite easy ways of advicing these calls manually, with a
pointcut on call(Class.newInstance(...)) and then manually calling the
advice body depending on the class and the parameters, but it's quite
overkill and should be used only when really really necessary.
Luca Ferrari wrote:
> On Tuesday 25 November 2008 17:21:39 Simone Gianni wrote:
>> Hi Andy,
>> unfortunately Spring uses reflection to create new objects, and
>> invocation of methods (or constructors) using reflection is not trapped
>> by AspectJ.
> Why not? After all creating a new object with reflection resolves in invoking
> the null-argument constructor, so why should AspectJ don't trap the
> constructor call?
> aspectj-users mailing list
Simone Gianni CEO Semeru s.r.l. Apache Committer