Hacking MoSKito, fixing AspectJ

Back in the MoSKito 1.2.0 Vitaliy added AspectJ annotations to MoSKito which was a great thing and provides a very easy and convenient way to integrate MoSKito into an application. After I recently added Counters I thought it would be a good idea to add an Aspect for it too.

Basically counters are different from other stats but not that different. For example both aspects needed some infrastructure to create OnDemandProducers and stats. It was obvious that a common superclass providing this infrastructural tasks was needed:

public class AbstractMoskitoAspect<S extends IStats> {

 * Map with created producers.
 private ConcurrentMap<String, OnDemandStatsProducer<S>> producers = new ConcurrentHashMap<String, OnDemandStatsProducer<S>>();

 * Returns the producer for the given pjp and producerId. Registers the producer in the registry if it's not already registered.
 * @param pjp the pjp is used to obtain the producer id automatically if it's not submitted.
 * @param aProducerId submitted producer id, used if configured in aop.
 * @param aCategory submitted category.
 * @param aSubsystem submitted subsystem.
 * @param withMethod if true the name of the method will be part of the automatically generated producer id.
 * @return
 protected OnDemandStatsProducer<S> getProducer(ProceedingJoinPoint pjp, String aProducerId, String aCategory, String aSubsystem, boolean withMethod, IOnDemandStatsFactory<S> factory){

With such superclass my both Aspects would be pretty straight forward:

public class MonitoringAspect extends AbstractMoskitoAspect<ServiceStats>{

@Around(value = "execution(* *(..)) && (@annotation(method))")
 public Object doProfilingMethod(ProceedingJoinPoint pjp, Monitor method) throws Throwable {


public class CounterAspect extends AbstractMoskitoAspect <CounterStats>{

@Around(value = "execution(* *(..)) && (@annotation(method))")
 public Object countMethod(ProceedingJoinPoint pjp, Count method) throws Throwable {

However my IDE (IntelliJ) didn’t like this code and neither did maven. The exception would be a very weird, especially in maven with one message:

the parameter pjp is not bound in [all branches of] pointcut


I googled around but didn’t find any solutions. So aspectj mailing list was my last hope, and that hope brought the solution, in this case in person of Andy Clement who confirmed this as bug, filed the bug, and also fixed it within 15 minutes of submission. That’s really fast, I would say almost as fast as we are, if you find a bug in MoSKito itself 😉

However, thanx Andy for help, and if you want to use generics in your aspects and can’t, 1.7.2 is your hope and rescue!

Hack on.

Leave a Reply

Your email address will not be published. Required fields are marked *