Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] null thisJoinPointStaticPart when advising constructor execution

I am guessing the scenario you showed (the way the ctors were mixed
up) can't be very common at all - since I've not had this issue
reported before against AspectJ.  There are other routes that could be
used to build the state so it wasn't null but given the how rarely
this occurs (and the work required to address it), I'm not sure fixing
it would be a high priority right now.

Can you use constructor call instead of execution and still achieve
what you want to? That may work better.

Regardless, it might be worth you raising a bugzilla for this so that
it isn't forgotten:
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ

cheers,
Andy

On 19 March 2010 16:42, Hagai Cibulski <hagaic@xxxxxxxxx> wrote:
> What I'm trying to do is use AspectJ to build a variant of coverage tool.
>
> It is something similar to JTestMe (which also uses AspectJ).
>
> This tool is supposed to run on any Java application that has JUnit tests,
> so I can't control or change the code to avoid this type of problem.
>
>
>
> Does this mean I can't always collect coverage data from execution of
> constructors?
>
>
>
> Thanks,
>
> Hagai
>
>
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement
> Sent: Friday, March 19, 2010 9:38 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] null thisJoinPointStaticPart when advising
> constructor execution
>
>
>
> Here is some pure Java code that shows what you are hitting:
>
> ---
>
> public class A {
>
>   public static void main(String []argv) {
>
>     new C();
>
>   }
>
>   static String get() { return "abc";}
>
> }
>
>
>
> class B {
>
>   static C b = new C();
>
> }
>
>
>
> class C extends B {
>
>   final static String str = A.get();
>
>
>
>   public C() {
>
>     System.out.println(str);
>
>   }
>
> }
>
> ---
>
> when run it prints:
>
> null
>
> abc
>
>
>
> This is because a condition of initializing C is that B is
>
> initialized.  B's static initializer will call back to C - which
>
> hasn't had the initializer run yet, so the field 'str' is null.  If I
>
> replace 'str' with thisJoinPointStaticPart, then that is the problem
>
> AspectJ is triggering with the code it is creating.
>
>
>
> Andy
>
>
>
> On 18 March 2010 14:35, Hagai Cibulski <hagaic@xxxxxxxxx> wrote:
>
>> Here is a variation on your program that recreates the problem:
>
>>
>
>>
>
>>
>
>> aspect Test {
>
>>
>
>>       public static void main(String[] argv) {
>
>>
>
>>             new C();
>
>>
>
>>       }
>
>>
>
>>
>
>>
>
>>       pointcut methodUnderTestExecution1() :
>
>>
>
>>             (execution(* *(..)) || execution(new(..))) && !within(Test);
>
>>
>
>>
>
>>
>
>>       before(): methodUnderTestExecution1() {
>
>>
>
>>             Object sig = thisJoinPointStaticPart.getSignature(); // null L
>
>>
>
>>             System.out.println(sig);
>
>>
>
>>       }
>
>>
>
>> }
>
>>
>
>>
>
>>
>
>> class B {
>
>>
>
>>       static C b = new C();
>
>>
>
>> }
>
>>
>
>> class C extends B {
>
>>
>
>> }
>
>>
>
>>
>
>>
>
>> -----Original Message-----
>
>> From: aspectj-users-bounces@xxxxxxxxxxx
>
>> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement
>
>> Sent: Thursday, March 18, 2010 10:20 PM
>
>> To: aspectj-users@xxxxxxxxxxx
>
>> Subject: Re: [aspectj-users] null thisJoinPointStaticPart when advising
>
>> constructor execution
>
>>
>
>>
>
>>
>
>> Can you tell me what kind of constructors lead to that being null?  A
>
>>
>
>> simple (complete) program that fails would be great.  This program:
>
>>
>
>>
>
>>
>
>> ---
>
>>
>
>> aspect Test {
>
>>
>
>>   public static void main(String []argv) {
>
>>
>
>>     new C();
>
>>
>
>>   }
>
>>
>
>>
>
>>
>
>>  pointcut methodUnderTestExecution1() :
>
>>
>
>>             (execution(* *(..)) || execution(new(..))) && !within(Test);
>
>>
>
>>
>
>>
>
>>   before(): methodUnderTestExecution1() {
>
>>
>
>>         Object sig = thisJoinPointStaticPart.getSignature();
>
>>
>
>>       System.out.println(sig);
>
>>
>
>>   }
>
>>
>
>>
>
>>
>
>> }
>
>>
>
>>
>
>>
>
>> class C { }
>
>>
>
>> ---
>
>>
>
>>
>
>>
>
>> works fine and prints C().
>
>>
>
>>
>
>>
>
>> cheers
>
>>
>
>> Andy
>
>>
>
>>
>
>>
>
>> On 18 March 2010 13:09, Hagai Cibulski <hagaic@xxxxxxxxx> wrote:
>
>>
>
>>> Hi All!
>
>>
>
>>>
>
>>
>
>>> Could use some help here…
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> I'm tracing methods execution stemming from JUnit tests using AspectJ,
>
>>> using
>
>>
>
>>> the following pointcut:
>
>>
>
>>>
>
>>
>
>>>       pointcut methodUnderTestExecution() :
>
>>
>
>>>
>
>>
>
>>>             execution(* *(..))
>
>>
>
>>>
>
>>
>
>>>             && mutFilter();
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> before(): methodUnderTestExecution() {
>
>>
>
>>>
>
>>
>
>>>             Signature sig = thisJoinPointStaticPart.getSignature();
>
>>
>
>>>
>
>>
>
>>>                         …
>
>>
>
>>>
>
>>
>
>>> So far, that works fine!
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> However, when trying to add constructor execution to the pointcut, I get
>
>>
>
>>> some unexpected behaviors:
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>       pointcut methodUnderTestExecution1() :
>
>>
>
>>>
>
>>
>
>>>             (execution(* *(..)) || execution(new(..)))
>
>>
>
>>>
>
>>
>
>>>             && mutFilter();
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> before(): methodUnderTestExecution1() {
>
>>
>
>>>
>
>>
>
>>>             Signature sig = thisJoinPointStaticPart.getSignature();
>
>>
>
>>>
>
>>
>
>>>             // thisJoinPointStaticPart == null L
>
>>
>
>>>
>
>>
>
>>>                         …
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> For some constructors in the application under test the advice causes
>
>>
>
>>> NullPointerException because thisJoinPointStaticPart == null
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Anyone?
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Thanks,
>
>>
>
>>>
>
>>
>
>>> Hagai
>
>>
>
>>>
>
>>
>
>>> _______________________________________________
>
>>
>
>>> aspectj-users mailing list
>
>>
>
>>> aspectj-users@xxxxxxxxxxx
>
>>
>
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>> _______________________________________________
>
>>
>
>> aspectj-users mailing list
>
>>
>
>> aspectj-users@xxxxxxxxxxx
>
>>
>
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>>
>
>> _______________________________________________
>
>> aspectj-users mailing list
>
>> aspectj-users@xxxxxxxxxxx
>
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>>
>
>>
>
> _______________________________________________
>
> aspectj-users mailing list
>
> aspectj-users@xxxxxxxxxxx
>
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top