2

Is there a way that we can view contents of dynamically generated java classes (like proxies generated by either JDKProxy or CGLIB) in some way - like in eclipse debugger view or have it printed on the log file on demand?

Kilokahn
  • 2,281
  • 1
  • 25
  • 50
  • What content? And why? – NilsH Mar 20 '13 at 05:21
  • I seem to be getting a NullPointerException in the generated code and wanted to know how to make sense of it. Knowing the contents of the code will probably help give some idea of why the NPE shows up? – Kilokahn Mar 20 '13 at 05:25
  • Proxies are dynamic. They implement an interface (or some times a class, if using CBLib) runtime based on reflection. So there is no "generated source code", if that's what you're after. In a JDK Proxy, you have an invocation handler that "implements" the proxy. I haven't used CBLIB that much, but they probably have a similar concept. So if you get an NPE, it's most likely that it is caused by something in your existing code. Showing us the code and the error might be more helpful. – NilsH Mar 20 '13 at 05:31
  • I am getting an exception like `Exception in thread "main" java.lang.NullPointerException at $Proxy45.conversionRate(Unknown Source)` which indicates that indicates that the error is coming really from the generated code and not any of the interceptors I had defined, right? Thanks in advance! – Kilokahn Mar 20 '13 at 05:34
  • It would be really helpful if you update your question with the complete stack trace and the code invoking the proxy. – NilsH Mar 20 '13 at 06:19
  • Thanks @NilsH - the code is available at https://github.com/kilokahn/spring-testers/tree/master/spring-proxy-proxy-tester - Running ProxyProxyDriver gives the following exception trace: `Exception in thread "main" java.lang.NullPointerException at $Proxy45.conversionRate(Unknown Source) at com.kilo.ProxyProxyDriver.makeServiceCalls(ProxyProxyDriver.java:41) at com.kilo.ProxyProxyDriver.main(ProxyProxyDriver.java:27)` – Kilokahn Mar 20 '13 at 07:24

1 Answers1

0

Does it work without aspects configured? I suggest that you take a look at the documentation for ProceedingJoinPoint.proceed() again, and then compare it to what your aspects actually are doing.

Edit: Here's a hint

@Aspect
public class AstralMethodInterceptor {

    private static final Logger LOG = LoggerFactory
            .getLogger(AstralMethodInterceptor.class);

    @Around("(execution(* com.kilo.proxyproxy.*.*(..)) || execution(* net.webservicex.*.*(..)) )")
    public void handleMethod(ProceedingJoinPoint pjp) throws Throwable {
        LOG.info("I encountered astral method in "
            + pjp.getThis().getClass().getCanonicalName());
        pjp.proceed();
    }
}
NilsH
  • 13,705
  • 4
  • 41
  • 59