Search code examples
javaaspectjcodahale-metrics

metrics-aspectj @Timed method on base class throws NullPointerException when class is extended


I have been using metrics-aspectj library and found it very convenient to annotate a method to capture performance metrics. Recently I hit the wall when trying the extend a class that has annotated methods. Here's what I see:

@Metrics
public class Base {
    public void something_not_timed() {
        ...
    }

    @Timed(name="method1-ProcessTime")
    public void method1() {
       ...
    }
}

I have been using Base class in production without issue. Now I need to extend this class.

public class Derived extends Base {
    @Override
    public void something_not_timed() {
        ....
    }
}

As you can see, method1() is not overridden. But the problem is that whenever I use method1() in Derived class, I would get a NullPointerException in method1_aroundBody1$advice().

I'm not familiar with AspectJ so couldn't really figure out what I'm missing, any advice will be highly appreciated.

Thanks!

Regards, Cary


Solution

  • It is a bug in metrics-aspectj. You have opened a ticket for it anyway, I noticed. I have created a little demontration repository for the problem and described it in more detail in my answer to your GitHub ticket.