Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between PMD and FindBugs?

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 difference is that PMD works on source code, while FindBugs works on compiled bytecode files. But in terms of capabilities, should it be an either/or choice or do they complement each other?

like image 886
Thomas Owens Avatar asked Nov 28 '10 13:11

Thomas Owens


People also ask

What is PMD checkstyle FindBugs?

PMD, FindBugs and Checkstyle, are the most popular open-source code analyzers, they are extensively used in Java development to improve the codebase and identify potential vulnerabilities along with design flaws; every tool has its feature, purpose and strength, targeting a specific type of coding rules.

What is the difference between FindBugs and SpotBugs?

Find bugs in Java Programs It is free software, distributed under the terms of the GNU Lesser General Public License. SpotBugs is a fork of FindBugs (which is now an abandoned project), carrying on from the point where it left off with support of its community. Please check the official manual for details.

Is SonarQube replacing checkstyle PMD FindBugs?

Yes and no. In addition to the other answers. SonarQube is currently on the way to deprecate PMD, Checkstyle and Findbugs and use their own technology to analyze Java code (called SonarJava).

What is the use of FindBugs?

FindBugs is an open source tool used to perform static analysis on Java code. In this article, we're going to have a look at setting up FindBugs on a Java project and integrating it into the IDE and the Maven build.


3 Answers

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.

like image 87
snakile Avatar answered Oct 16 '22 22:10

snakile


The best feature of PMD, is its XPath Rules, bundled with a Rule Designer to let you easily construct new rules from code samples (similar to RegEx and XPath GUI builders). FindBugs is stronger out of the box, but constructing project specific rules and patterns is very important.

For example, I encountered a performance problem involving 2 nested for loops, resulting in a O(n^2) running time, which could easily be avoided. I used PMD to construct an ad-hoc query, to review other instances of nested for loops - //ForStatement/Statement//ForStatement. This pointed out 2 more instances of the problem. This is not a generic rule whatsoever.

like image 31
Dekel Avatar answered Oct 16 '22 22:10

Dekel


PMD is

  • famous
  • used widely in industry
  • you can add your rules in xml
  • gives you detailed analysis in Errors levels and warning levels
  • you can also scan your code for "copy and paste lines". Duplicate code. This gives good idea about implementing java oops.
like image 2
kunal saxena Avatar answered Oct 16 '22 22:10

kunal saxena