##### Overview

- Download PMD 5.0.4
- What's new in PMD 5.0.4
- 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
- PMD developers information
- PMD Release Process

##### For example

- Run PMD on a Sourceforge project

##### Misc.

- XPath tutorial (Gregorian)

##### Rule Sets

- ecmascript
  - Basic Ecmascript
  - Braces
  - Unnecessary
- java
  - Android
  - Basic
  - Braces
  - Clone Implementation
  - Code Size
  - Comments
  - Controversial
  - Coupling
  - Design
  - Empty Code
  - Finalizer
  - Import Statements
  - J2EE
  - JavaBeans
  - JUnit
  - Jakarta Commons Logging
  - Java Logging
  - Migration
  - Naming
  - Optimization
  - Strict Exceptions
  - String and StringBuffer
  - Security Code Guidelines
  - Type Resolution
  - Unnecessary
  - Unused Code
- jsp
  - Basic JSF
  - Basic JSP
- xml
  - Basic XML
- xsl
  - XPath in XSL

##### Project Documentation

- Project Information
- Project Reports

## Finalizer

These rules deal with different problems that can occur with finalizers.

### EmptyFinalizer

Since: PMD 1.5

Empty finalize methods serve no purpose and should be removed.

    //MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
      /Block[count(*)=0]

Example(s):

    public class Foo {
       protected void finalize() {}
    }

### FinalizeOnlyCallsSuperFinalize

Since: PMD 1.5

If the finalize() is implemented, it should do something besides just calling super.finalize().

    //MethodDeclaration[MethodDeclarator[@Image="finalize"][not(FormalParameters/*)]]
       /Block[count(BlockStatement)=1]
         /BlockStatement[
           Statement/StatementExpression/PrimaryExpression
           [./PrimaryPrefix[@SuperModifier='true']]
           [./PrimarySuffix[@Image='finalize']]
         ]

Example(s):

    protected void finalize() {
    	super.finalize();
    }

### FinalizeOverloaded

Since: PMD 1.5

Methods named finalize() should not have parameters. It is confusing and most likely an attempt to overload Object.finalize(). It will not be called by the VM.

    //MethodDeclaration
     /MethodDeclarator[@Image='finalize'][FormalParameters[count(*)>0]]

Example(s):

    public class Foo {
       // this is confusing and probably a bug
       protected void finalize(int a) {
       }
    }

### FinalizeDoesNotCallSuperFinalize

Since: PMD 1.5

If the finalize() is implemented, its last action should be to call super.finalize.

    //MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
       /Block
          /BlockStatement[last()]
          [not(Statement/StatementExpression/PrimaryExpression
                [./PrimaryPrefix[@SuperModifier='true']]
                [./PrimarySuffix[@Image='finalize']]
              )
          ]
          [not(Statement/TryStatement/FinallyStatement
           /Block/BlockStatement/Statement/StatementExpression/PrimaryExpression
                [./PrimaryPrefix[@SuperModifier='true']]
                [./PrimarySuffix[@Image='finalize']]
              )
          ]

Example(s):

    protected void finalize() {
    	something();
    	// neglected to call super.finalize()
    }

### FinalizeShouldBeProtected

Since: PMD 1.1

When overriding the finalize(), the new method should be set as protected. If made public, other classes may invoke it at inappropriate times.

    //MethodDeclaration[@Protected="false"]
      /MethodDeclarator[@Image="finalize"]
      [not(FormalParameters/*)]

Example(s):

    public void finalize() {
    	// do something
    }

### AvoidCallingFinalize

Since: PMD 3.0

The method Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. It should not be invoked by application logic.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.finalizers.AvoidCallingFinalizeRule

Example(s):

    void foo() {
    	Bar b = new Bar();
    	b.finalize();
    }

This rule has the following properties:

Name | Default Value | Description
violationSuppressRegex |  | Suppress violations with messages matching a regular expression
violationSuppressXPath |  | Suppress violations on nodes which match a given relative XPath expression.