Skip to main content

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

Hi Andy,
unfortunately Spring uses reflection to create new objects, and
invocation of methods (or constructors) using reflection is not trapped
by AspectJ.

AspectJ is missing a joinpoint like "An object, subclass of Xyz, has
been completely constructed", and this problem raises from time to time
here on the mailing list. But there are a few workarounds, we had quite
a coverage of it a few months ago, search the thread "Advice on
Constructors With Subclasses" in September. In one of the last messages,
I posted a possible solution for the problem.

Anyway, in your specific case, the code of your advice will be inlined
with the original constructor, after the original constructor code, so,
As Eric already pointed out, I don't see any additional problem from the
aspect itself.

Simone


Andy Kriger wrote:
> Thank you for confirming my suspicion.
>
> Can call work at compile-time if we're using a 3rd party library like
> Spring that creates objects using its own code via reflection? Would
> the call pointcut require compiling Spring's code w aspects (rather
> than just our code)? Or would this require us to use run-time weaving?
>
> On Tue, Nov 25, 2008 at 10:50 AM, Eric Bodden
> <eric.bodden@xxxxxxxxxxxxxx> wrote:
>   
>>> Does the advice run before the constructor has finished, thus exposing
>>> this in a non-threadsafe manner?
>>>       
>> AFAIK it doesn't. Your code will run just at the end of the
>> constructor (inside it).
>>
>>     
>>> What is a better way to write this advice such that something happens
>>> after the constructor has completed?
>>>       
>> after() returning(Listener l): call((@MyAnnotation *).new(..)) {
>> ..
>> }
>>
>> Eric
>>
>> --
>> Eric Bodden
>> Sable Research Group, McGill University, Montréal, Canada
>> Got an interesting job offer? http://www.bodden.de/hire-me/
>>
>>     
>
>
>
>   


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



Back to the top