How to replace type instance by wrapping around constructor?

I have an obsolete lib that instantiates BeanProxy . Unfortunately, this implementation has a flaw that I would like to fix. Since I do not want to start working with patched libraries, I would like to create an Aspect that completes the BeanProxy construct and returns an instance of my modified BeanProxy subtype.

I created the following Aspect and it is properly gossiped and called whenever a new BeanProxy instance is BeanProxy :

 @Aspect public class CWebBeanProxyInjectingAspect { @Pointcut("execution(public flex.messaging.io.BeanProxy.new(..))") void createBeanProxy() {} @Around("createBeanProxy()") public Object createAlternateBeanProxy(final ProceedingJoinPoint pjp) throws Throwable { System.out.println("createAlternateBeanProxy"); final Object result = pjp.proceed(); System.out.println(result); return result; } } 

Unfortunately, result always null ... what am I doing wrong? What do i need to change? It should be noted that I use AspectJ LoadTimeWeaving and spring -instrument-3.1.1.RELEASE.jar as an agent.

+4
source share
1 answer

The execution constructor returns nothing (there is void ). If you want to return the created object, use call in pointcut:

  @Pointcut("call(public flex.messaging.io.BeanProxy.new(..))") void createBeanProxy() {} 

see calling the Constructor and executing the constructor at http://www.eclipse.org/aspectj/doc/next/progguide/semantics-joinPoints.html

+1
source

All Articles