Saturday, February 7, 2009

Detect commonly occurring defects with PMD, Findbugs and Jlint

A compiler may have difficulty in finding some commonly occurring defects such as null assignment, empty catch block, catching the canonical Exception instead of a specific one, etc. Dr. Eric Allen lists many instances of these defects in his book ‘Java Bug Patterns’.

PMD can detect such defects in a given set of Java source file once they are described as ‘patterns’. PMD rules can be written in java.

FindBugs & JLint can detect common defects by reviewing the class files. JLint can detect inconsistencies and synchronization problems.

CPD – a variant of the PMD is used for detecting instances of code that has been copy-pasted. Duplication of code indicates non-existence of single point of control. A bug can propagate to other parts of the code if the base code contains bug in it. CPD thus can denote code that needs to be refactored.

http://pmd.sourceforge.net/
http://findbugs.sourceforge.net/
http://jlint.sourceforge.net/

These tools are very interesting and simple to use.


No comments:

Post a Comment