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

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


Back to the top