Fork me on GitHub

Unused Code

The Unused Code ruleset contains rules that find unused or ineffective code.

UnusedPrivateField

Since: PMD 0.1

Priority: 3

Detects when a private field is declared and/or assigned a value, but not used.

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

Example(s):


public class Something {
  private static int FOO = 2; // Unused
  private int i = 5; // Unused
  private int j = 6;
  public int addOne() {
    return j++;
  }
}

    

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.

UnusedLocalVariable

Since: PMD 0.1

Priority: 3

Detects when a local variable is declared and/or assigned, but not used.

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

Example(s):


public class Foo {
	public void doSomething() {
		int i = 5; // Unused
	}
}

    

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.

UnusedPrivateMethod

Since: PMD 0.7

Priority: 3

Unused Private Method detects when a private method is declared but is unused.

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

Example(s):


public class Something {
	private void foo() {} // unused
}

    

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.

UnusedFormalParameter

Since: PMD 0.8

Priority: 3

Avoid passing parameters to methods or constructors without actually referencing them in the method body.

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

Example(s):


public class Foo {
	private void bar(String howdy) {
	// howdy is not used
	}
}

    

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.
checkAll false Check all methods, including non-private ones