Bug 127265 - Support compiler warning for swallowed exception in catch block
Summary: Support compiler warning for swallowed exception in catch block
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 127287
  Show dependency tree
 
Reported: 2006-02-10 10:12 EST by Adrian Colyer CLA
Modified: 2007-07-29 09:18 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Colyer CLA 2006-02-10 10:12:11 EST
So many people have asked how to write a declare warning / error to detect empty catch blocks, that this is clearly a desirable feature.

But it's impossible with declare warning / error.

And it's pretty hard in byte code (the old "what's the end of a catch block" problem).

But it's not hard if you've got a compiler. So why don't we just add a new front-end compiler warning (works only when building from source) on swallowed exceptions. This would behave like the existing "undocumentedEmptyBlock" warning, except be specific to catch blocks so that you can turn it on without getting lots of warnings you don't want in many other places.
Comment 1 Adrian Colyer CLA 2006-02-10 10:16:43 EST
Surprise!

I've got this working in my workspace. (Using a simple aspect to detect the condition and punt out the problem). Severity is controllable via Xlint:swallowedExceptionInCatchBlock. Hardest part was getting the JDT compiler options configured from an XLint setting!

It works like this:

catch(NoSuchMethodException ex) {}
                                                      ^^

Blah.java:42:0 Exception swallowed in catch block

We should try and get this picked up by the JDT themselves in time...

Comment 2 Adrian Colyer CLA 2006-02-10 10:17:54 EST
(you wouldn't believe how many swallowed exceptions in catch blocks there are in our test suite! :( )
Comment 3 Andrew Clement CLA 2006-02-10 11:11:52 EST
Given all the warnings you can get out from the JDT compiler already - i'm surprised empty catch blocks isnt in there already... have you checked?
Comment 4 Adrian Colyer CLA 2006-02-10 11:49:22 EST
yep - they have "undocumented empty block" - which does catch empty catch blocks, but also a whole bunch of other stuff so you never turn it on. 

this one is just for catch blocks, so you can control the level for them independently. I didn't look in 3.2, but it will be a while before we bite that bullet anyway...
Comment 5 Matt Chapman CLA 2006-04-03 12:28:22 EDT
The default for this option appears to be "warning". I'd say "ignore" would be a better default, as this option doesn't relate specifically to aop - in fact our FFDC aspect in ajdt means we have lots of empty catch blocks, in which case the warning is rather annoying.
Comment 6 Matt Chapman CLA 2006-06-16 07:37:55 EDT
I see this bug is still open... are you going to change the default setting for this option? Enabling it by default isn't helpful, it just clutters up build reports.
Comment 7 Adrian Colyer CLA 2006-06-19 13:27:58 EDT
default now changed to ignore, will be in the next build but I'm closing this bug report now instead of waiting since it's so minor...
Comment 8 Eclipse Webmaster CLA 2007-07-29 09:18:55 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991