Re: IllegalCatch extension.
"Emerson Farrugia" <[email protected]>
| Newsgroups | gmane.comp.java.audit.checkstyle.user |
|---|---|
| Message-ID | <[email protected]> |
It has come to my attention that FindBugs recognises this scenario
using the REC_CATCH_EXCEPTION bug pattern. Its documentation follows:
REC: Exception is caught when Exception is not thrown (REC_CATCH_EXCEPTION)
This method uses a try-catch block that catches Exception objects, but
Exception is not thrown within the try block, and RuntimeException is
not explicitly caught. It is a common bug pattern to say try { ... }
catch (Exception e) { something } as a shorthand for catching a number
of types of exception each of whose catch blocks is identical, but
this construct also accidentally catches RuntimeException as well,
masking potential bugs.
On 25/01/2008, Emerson Farrugia <[email protected]> wrote:
> Thanks for the reply.
>
> The number of try blocks that throw Exception is quite small in the
> code base, so using the suppression filter comment is not a major
> inconvenience. I did have two concerns about using suppression
> comments:
>
>
> 1. Coupling the code to Checkstyle. The developer shouldn't need to
> concern himself with Checkstyle, and adding comments which make
> references to Checkstyle may be seen as polluting the code. I'll
> mitigate this by setting generic and meaningful short strings for the
> Off and On comments.
>
> 2. Performance. I didn't know if the FileContentsHolder module would
> slow down Checkstyle. It doesn't seem to, judging by some quick and
> dirty tests.
>
>
> Thanks for any feedback, regards,
> Emerson
>
>
> On 24/01/2008, Oliver Burn <[email protected]> wrote:
> > Hi, that information is not available to the check to make this smart
> > decision.
> >
> > In reality the only option is to use the Suppression Filter as you currently
> > doing.
> >
> > In practice if the use of the API is encapsulated, it should not be a major
> > inconvenience. But, if the API is used all throughout your code
> > base.................
> >
> > Cheers,
> > Oliver
> >
> >
> > On Jan 25, 2008 1:26 AM, Emerson Farrugia <[email protected]>
> > wrote:
> > >
> > > Hi,
> > >
> > > The IllegalCatch check determines if a catch block is trapping generic
> > > exceptions, such as Exception, Error, RuntimeException, and Throwable.
> > >
> > > I'd like to enable this check. However, there are cases when Exception
> > > must be caught by the programmer. This often occurs when using
> > > third-party libraries whose methods throw Exception, such as the
> > > Velocity.mergeTemplate() method.
> > >
> > > Is it possible for the check to be extended such that an event isn't
> > > trigger if the try block throws Exception? I don't know if that
> > > information is available to the check.
> > >
> > > Until then, I'll use a suppression filter.
> > >
> > > Thanks,
> > > Emerson
> > >
> > >
> > -------------------------------------------------------------------------
> > > This SF.net email is sponsored by: Microsoft
> > > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > > _______________________________________________
> > > Checkstyle-user mailing list
> > > [email protected]
> > >
> > https://lists.sourceforge.net/lists/listinfo/checkstyle-user
> > >
> >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Checkstyle-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/checkstyle-user
> >
> >
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/