Tuesday 30 July 2013

Understanding where code gets fired from

Problem: you use a component (in our case, a SelectOneBoolean) which has its selected value is stored within a bean. The setter to this gets called multiple times on a page load (this is normal) but during navigation of the page, the setter was being called from an unknown place, causing a bug in our UI.

Now, to solve this, you cant really use the debugger because you know where the problem lies, but you dont know the calling code.

A good solution, to understand the route of methods being called, is to introduce an exception. Its a strange concept but is good for things like this.

Add the following code to get a stack trace of the methods fired to give you a better understanding of what is going on within your ADF pages.

try {
    throw new Exception("");
} catch (Exception e){
    e.printStackTrace();
}

To clairfy, you simply generate an exception, print out the stack trace and carry on processing the application logic.

We eventually found the issue relatively quickly within one of the methods prior to the setter being called.

I hope this helps somebody; somebody scratching their head over a problem of "why and where is this being called from."


It shouldnt need to be said, but do +NOT+ go into production with these still present.

1 comment:

  1. Simple and good debugging technique. Thanks for sharing the idea.

    ReplyDelete