Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Static Analysis > Source Analysis

Source Analysis

As the name implies, source analysis tools look at your source code, searching for bug patterns. The tool I used in the following code is PMD, an open source tool for Java. PMD offers a command-line version, Ant support, and plug-ins for all major development environments. It looks for problems in the following categories:

Possible bugs

For example, empty try...catch blocks

Dead code

Unused local variables, parameters, and private variables

Suboptimal code

Wasteful string usage

Overcomplicated expressions

“Reuse” via copy and paste

Duplicate code (supported by an ancillary tool called CPD)

“Reuse” via copy and paste

PMD falls somewhere between pure style checkers (like CheckStyle, which makes sure that your code adheres to certain style guidelines like indentation) and FindBugs, which looks at byte code. As an example of the kinds of errors for which PMD excels, consider this Java method:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint