Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find where a specific thrown exception could be caught in eclipse?

I'm trying to trace a IO resource leak, where a connection is opened, but not necessarily closed:

try{ 
     ...
     urlConnection.connect();
     ...
     connectionResult.setResultInputStream(urlConnection.getInputStream());
     return connectionResult;

} catch (IOException e) {
     throw new ValidationException(e, new LocationData(submissionURL.toExternalForm(), -1, -1));
}

Is there a way I can find out where ValidationException will be caught through the call hierarchy? The manual steps are something like:

  1. Do call heirarchy of containing method
  2. For each caller:
    • Analyse surrounding code, finding try catch blocks
    • If exception caught, evaluate stream closing
    • If not, repeat 1.

Notes

  • This is not reproducible; only one customer has this issue in their failover environment - the product version is 5 years old, and has never shown issues like this before.
  • I can find all cases where the exception is thrown; I want to find where this particular thrown exception could be caught (including catch Exception etc)
like image 527
Stephen Avatar asked May 10 '11 04:05

Stephen


1 Answers

This is certainly not supported by Eclipse "out of the box". Their might be an Eclipse plugin that supports this, but I've not heard of one. (This is something that you rarely need to do in practice ... so there's little justification for going to the effort of implementing this.)

One alternative to code analysis is to hack the code to throw the exception under some circumstance that you can control, and then use the Java debugger to see where it actually gets caught.

Another alternative might be to hack together a custom PMD rule to identify the relevant catches. I don't think it would be simple though ...

like image 174
Stephen C Avatar answered Oct 22 '22 22:10

Stephen C