Question

Could you let me know taht Findbugs can detect catcing RuntimeException in java?

Effective java recommends that we should not catch RuntimeException.

So I want to know that Findbugs can grab wrong catching.

Additionally, I already checked Klocwork JD.CATCH and checkstyle IllegalCatch is appropriate for this purpose.

Was it helpful?

Solution

Sort of. In findbugs there are several bug detectors dealing with exceptions:

  • DE: Method might drop exception
  • DE: Method might ignore exception
  • Nm: Class is not derived from an Exception, even though it is named as such
  • RV: Exception created and dropped rather than thrown
  • REC: Exception is caught when Exception is not thrown

and also findbugs-contrib (findbugs plugin) has some:

  • BED_BOGUS_EXCEPTION_DECLARATION
  • DRE_DECLARED_RUNTIME_EXCEPTION
  • EXS_EXCEPTION_SOFTENING_NO_CHECKED
  • EXS_EXCEPTION_SOFTENING_HAS_CHECKED
  • EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS

Try those out and check if they match your requirements (especially the last one (REC) of fb). However if you plainly need to detect the following pattern:

catch ( RuntimeException re){
    ....            
}

You may need to implement your own (quite easy) bug pattern for findbugs...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top