Java Code Review Tools Analysis
Java Code Review Tools Analysis
FindBugs
Based on the concept of bug patterns. A bug pattern is a code idiom that is often an error.
Difficult language features Misunderstood API methods Misunderstood invariants when code is modified during maintenance Garden variety mistakes: typos, use of the wrong Boolean operator
FindBugs uses static analysis to inspect Java bytecode for occurrences of bug patterns. Static analysis means that FindBugs can find bugs by simply inspecting a program's code: executing the program is not necessary. FindBugs works by analyzing Java bytecode (compiled class files), so you don't even need the program's source code to use it. FindBugs can report false warnings, not indicate real errors. In practice, the rate of false warnings reported by FindBugs is less than 50%.
FindBugs Categories
Bad practice Correctness Dodgy Experimental Internationalization Malicious code vulnerability Multithreaded correctness Performance Security
FindBugs Report
FindBugs Detail
PMD
PMD scans Java source code and looks for potential problems like: Possible bugs - empty try/catch/finally/switch statements Dead code - unused local variables, parameters and private methods Suboptimal code - wasteful String/StringBuffer usage Overcomplicated expressions - unnecessary if statements, for loops that could be while loops Duplicate code - copied/pasted code means copied/pasted bugs
PMD RuleSets
Android Rules: These rules deal with the Android SDK. Basic JSF rules: Rules concerning basic JSF guidelines. Basic JSP rules: Rules concerning basic JSP guidelines. Basic Rules: The Basic Ruleset contains a collection of good practices which everyone should follow. Braces Rules: The Braces Ruleset contains a collection of braces rules. Clone Implementation Rules: The Clone Implementation rule set contains a collection of rules that find questionable usages of the clone() method. Code Size Rules: The Code Size Ruleset contains a collection of rules that find code size related problems. Controversial Rules: The Controversial Ruleset contains rules that, for whatever reason, are considered controversial. Coupling Rules: These are rules which find instances of high or inappropriate coupling between objects and packages. Design Rules: The Design Ruleset contains a collection of rules that find questionable designs. Import Statement Rules: These rules deal with different problems that can occur with a class' import statements.
J2EE Rules: These are rules for J2EE JavaBean Rules: The JavaBeans Ruleset catches instances of bean rules not being followed. JUnit Rules: These rules deal with different problems that can occur with JUnit tests. Jakarta Commons Logging Rules: Logging ruleset contains a collection of rules that find questionable usages.
PMD Ruleset
Continue
Java Logging Rules: The Java Logging ruleset contains a collection of rules that find questionable usages of the logger. Migration Rules: Contains rules about migrating from one JDK version to another. Migration15: Contains rules for migrating to JDK 1.5 Naming Rules: The Naming Ruleset contains a collection of rules about names too long, too short, and so forth. Optimization Rules: These rules deal with different optimizations that generally apply to performance best practices. Strict Exception Rules: These rules provide some strict guidelines about throwing and catching exceptions. String and StringBuffer Rules: Problems that can occur with manipulation of the class String or StringBuffer. Security Code Guidelines: These rules check the security guidelines from Sun. Type Resolution Rules: These are rules which resolve java Class files for comparisson, as opposed to a String Unused Code Rules: The Unused Code Ruleset contains a collection of rules that find unused code.
PMD Configuration
<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> <rulesets> <ruleset>/rulesets/braces.xml</ruleset> <ruleset>/rulesets/naming.xml</ruleset> <ruleset>d:\rulesets\strings.xml</ruleset> <ruleset>http://localhost/design.xml</ruleset> </rulesets> </configuration> </plugin> </plugins> </reporting>
CheckStyle
Development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. Highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. Other sample configuration files are supplied for other well known conventions.
CheckStyle Example
Sonar
Dashboard to summarize Static and Dynamic analysis Tools. Conventions (Checkstyle) Bad Practices (PMD) Potential Bugs (FindBugs)
Sonar Components
Sonar Hotspots
Sonar Drilldown
IntelliJ Idea
IDE Features Code Duplicates Code Coverage Code Inspector Spell Checker Community Edition No No Yes Yes Ultimate Edition Yes Yes Yes Yes
More than 600 automated Code Inspections Finding probable bugs Locating the dead code Detecting performance issues Improving code structure and maintainability Conforming to coding guidelines and standards Conforming to specifications