What are the differences between PMD and FindBugs?

后端 未结 3 2041
醉酒成梦
醉酒成梦 2020-12-22 20:19

There was a question comparing PMD and CheckStyle. However, I can\'t find a nice breakdown on the differences/similarities between PMD and FindBugs. I believe a key differen

3条回答
  •  一整个雨季
    2020-12-22 21:18

    I'm using both. I think they complement each other.

    As you said, PMD works on source code and therefore finds problems like: violation of naming conventions, lack of curly braces, misplaced null check, long parameter list, unnecessary constructor, missing break in switch, etc. PMD also tells you about the Cyclomatic complexity of your code which I find very helpful (FindBugs doesn't tell you about the Cyclomatic complexity).

    FindBugs works on bytecode. Here are some problems FindBugs finds which PMD doesn't: equals() method fails on subtypes, clone method may return null, reference comparison of Boolean values, impossible cast, 32bit int shifted by an amount not in the range of 0-31, a collection which contains itself, equals method always returns true, an infinite loop, etc.

    Usually each of them finds a different set of problems. Use both. These tools taught me a lot about how to write good Java code.

提交回复
热议问题