This content has been marked as final.
Show 2 replies
-
1. Re: null returned
kabirkhan Jul 9, 2005 7:25 AM (in response to oberon777)I am sure we have tests in our testsuite for this. In any case I gave it a go, and it worked for me.
public class ConstructorInterceptor implements Interceptor { public String getName() { return "ConstructorInterceptor"; } public Object invoke(Invocation invocation) throws Throwable { try { System.out.println("<<< Doing it"); Object o = invocation.invokeNext(); System.out.println("Got o " + (o != null)); return o; } finally { System.out.println(">>> Leaving ConstructorInterceptor"); } } }
<aop> <bind pointcut="call(* java.lang.Class->newInstance(..))"> <interceptor class="ConstructorInterceptor"/> </bind> </aop>
public class Driver { public static void main(String[] args) throws Exception { Class clazz = POJO.class; System.out.println("--- new POJO(); ---"); POJO pojo = (POJO)clazz.newInstance(); System.out.println("Got pojo " + (pojo != null)); } }
<?xml version="1.0" encoding="UTF-8"?> <aop> <bind pointcut="call(* java.lang.Class->newInstance(..))"> <interceptor class="ConstructorInterceptor"/> </bind> </aop>
Output:[java] --- new POJO(); --- [java] <<< Doing it [java] empty constructor [java] Got o true [java] >>> Leaving ConstructorInterceptor [java] Got pojo true
-
2. Re: null returned
oberon777 Jul 11, 2005 4:27 PM (in response to oberon777)Hmm.. thanks for such a detailed reply. I'll experiment some more to see what was causing this issue.