##### Overview

- Download PMD 4.2.5
- What's new in PMD 4.2.5
- PMD in the news
- PMD-related products and books
- Best practices
- Future directions
- Similar projects
- Credits
- License
- What does 'PMD' mean?

##### Usage

- Installation
- Command line usage
- Ant task usage
- Maven plugin usage
- Mvn plugin usage
- IDE plugin usage
- Suppressing warnings
- Finding duplicated code
- JSP support

##### Customizing PMD

- Compiling PMD
- How to write a rule
- Writing XPath rules
- How to make a rule set
- How it works
- Rule guidelines

##### For example

- Run PMD on a Sourceforge project

##### Rule Sets

- Index
- Android
- Basic
- Braces
- Code Size
- Clone
- Controversial
- Coupling
- Design
- Finalizers
- Import Statements
- J2EE
- Javabeans
- JUnit Tests
- Logging (Java)
- Logging (Jakarta)
- Migrating
- Naming
- Optimizations
- Strict Exceptions
- Strings
- Sun Security
- Unused Code
- Java Server Pages
- Java Server Faces

##### Project Documentation

- About
- Project Info
- Project Reports
- Development Process

##### Legend

- External Link
- Opens in a new window

## Braces Rules

The Braces Ruleset contains a collection of braces rules.

### IfStmtsMustUseBraces

Since: PMD 1.0

Avoid using if statements without using curly braces.

This rule is defined by the following XPath expression:

    //IfStatement[count(*) &lt; 3][not(Statement/Block)]

Example:

     public class Foo {
       public void bar() {
         int x = 0;
         if (foo) x++;
       }
     }

### WhileLoopsMustUseBraces

Since: PMD 0.7

Avoid using 'while' statements without using curly braces.

This rule is defined by the following XPath expression:

    //WhileStatement[not(Statement/Block)]

Example:

    public void doSomething() {
      while (true)
          x++;
    }

### IfElseStmtsMustUseBraces

Since: PMD 0.2

Avoid using if..else statements without using curly braces.

This rule is defined by the following XPath expression:

    //Statement
     [parent::IfStatement[@Else='true']]
     [not(child::Block)]
     [not(child::IfStatement)]

Example:

     public void doSomething() {
       // this is OK
       if (foo) x++;
       // but this is not
       if (foo)
           x=x+1;
       else
           x=x-1;
     }

### ForLoopsMustUseBraces

Since: PMD 0.7

Avoid using 'for' statements without using curly braces.

This rule is defined by the following XPath expression:

    //ForStatement[not(Statement/Block)]

Example:

    public void foo() {
     for (int i=0; i<42;i++)
       foo();
    }