Summary
PMD is a Java code quality tool that scans Java source files, and matches a large set of rules on that source code to find potential bugs, errors, or just plain poor coding style. PMD's new 3.9 version includes a dozen additional rules, and provides a significant performance boost as well.
Advertisement
PMD is Java source scanner that inspects source code in order to identify potential problems. For example, PMD can find empty try-catch blocks, unnecessary if statements and for loops, unused variables, parameters, and private methods, and pinpoints duplicated code, i.e., code that resulted from copying-and-pasting from one area of a code base into another.
PMD relies on a set of rules about code in order to identify those problems. PMD's rules are grouped into rule sets, with sets addressing issues from basic coding style to code size, logging, String usage, unit testing, or JavaBeans and JSP pages.
BigIntegerInstantiation ensures that you don't unnecessarily initialize BigIntegers for which a constant is already defined, such as BigInteger.ZERO or BigInteger.ONE
The AvoidUsingOctalValues checks that you didn't inadvertently place a zero in front of integer constants: Doing so would cause the compiler to interpret those integers as octal values.
NPathComplexity. According to the PMD documentation:
NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
NcssTypeCount counts type declarations, including classes as well as enums and annotations.
NcssMethodCount counts the size of all non-constructor methods.
NcssConstructorCount counts constructor declarations, including any explicit super() calls.
UseCollectionIsEmpty checks if you're trying to compare the size of a collection to 0, as the Collection interface's isEmpty() method should be used to find if a collection has any elements.
StringBufferInstantiationWithChar If you try to instantiate a StringBuffer with an char, as in new StringBuffer('c'), the char will be converted to an int to initialize the StringBuffer's size.
What code checking rules do you find most useful in your projects?