Can Findbugs detect catching RuntimeException in java?

Could you tell me that Findbugs can detect RuntimeException caching in java?

Effective Java recommends not removing RuntimeException.

So, I want to know that Findbugs can capture the wrong trap.

In addition, I already checked Klocwork JD.CATCH and checkstyle IllegalCatch is suitable for this purpose.

+4
source share
1 answer

Grade. Findbugs has several exception detectors for errors:

  • DE: The method may throw an exception
  • DE: Method may ignore exception
  • Nm: A class is not derived from an exception, although it is named as such
  • RV: Exception thrown and deleted, not thrown
  • REC: An exception is thrown when an exception is not thrown.

as well as findbugs-contrib (the findbugs plugin) has several:

  • BED_BOGUS_EXCEPTION_DECLARATION
  • DRE_DECLARED_RUNTIME_EXCEPTION
  • EXS_EXCEPTION_SOFTENING_NO_CHECKED
  • EXS_EXCEPTION_SOFTENING_HAS_CHECKED
  • EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS

Try checking and checking to see if they meet your requirements (especially the last (REC) from fb). However, if you explicitly need to discover the following pattern:

catch ( RuntimeException re){ .... } 

You may need to implement your own (fairly simple) error pattern for findbugs ...

+2
source

Source: https://habr.com/ru/post/1497890/


All Articles