Wednesday, February 17, 2010

Why you should look at the exceptions tab when profiling

When profiling an application I always like to take a look at the Exceptions tab (I use Yourkit Java profiler). Frequent exceptions may show that something is going wrong and you don't know about it since someone preferred to swallow the exception and hope for the best.
Today, while trying to figure out a performance issue related to Classloader synchronization in Weblogic I noticed that IndexOutOfBoundsException is frequently thrown by the business layer of the application.

 

The code clearly speaks for itself:

   public Object getObject1() {
        try{
            return (Object )getObjectList().get(0);
        }
        catch(IndexOutOfBoundsException e){
            return null;
        }
    }

  public Object  getObject2() {
        try{
            return (Object )getObjectList().get(1);
        }
        catch(IndexOutOfBoundsException e){
            return null;
        }
    }

* Method and class names where altered  

No comments: