[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Question about constructor pointcuts

Ciao Luca,
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.

Simone

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


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/