4

So, I'm trying to fix a bug on a fairly complex Spring based webapp. The bug is a NullPointer Exception, but, rather unhelpfully, it's not returning a stacktrace or anything similarly helpful to let me know exactly where it is occurring.

Stepping through the execution of the programme with IntelliJ shows that the exception is occurring in a Spring Proxy object: $Proxy338 , but doesn't show the proxy code.

I'm sorry for being so vague: The error reporting on this bug is pretty unhelpful. Any suggestions for how I should proceed from here would be welcome: should I be looking for AOP/transaction code which is producing the failing proxy? Is there more information I could gather with IntelliJ which would let me pinpoint exactly what is going on?

RoryB
  • 1,047
  • 7
  • 28
  • It is not uncommon for a proxy to be not initialized and throw a NullPointer if the the getter for the object was not called. You can try to manually call the getter for this object to see if the proxy unproxies correctly if Hibernate proxied object or refer to this for AOP Spring proxy: http://stackoverflow.com/questions/8121551/is-it-possible-to-unproxy-a-spring-bean – Nikola Yovchev Dec 10 '12 at 10:27
  • Well you could try to search your code for catch blocks that only log the error and not the stacktrace. Maybe that gives you a clue. Or set an exception breakpoint in IntelliJ. – Hugo Dec 10 '12 at 10:31
  • Part of the problem is that I'm not exactly sure what the proxy object is doing. There's no annotation on the method, so part of my problem is finding where to look for the annotation code. Also, the exception is thrown as the method is returning, which suggests that the proxy is initialised correctly – RoryB Dec 10 '12 at 10:41
  • 1
    If you have a debugger session and the proxy is a Spring proxy you should be able to see its target by looking through its internal properties (it has an "h" usually that contains an Advised, and the Advised will have a target source). – Dave Syer Dec 10 '12 at 13:55

1 Answers1

7

You could also try retrieving the proxied object to see where exactly the NullPointerExeption is thrown.

To get the proxied object:

((Advised)yourProxy).getTargetSource().getTarget();
kyiu
  • 1,926
  • 1
  • 24
  • 30